-
-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1386 from pierotofy/console
Move task.console_output
- Loading branch information
Showing
9 changed files
with
125 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import os | ||
import logging | ||
logger = logging.getLogger('app.logger') | ||
|
||
class Console: | ||
def __init__(self, file): | ||
self.file = file | ||
self.base_dir = os.path.dirname(self.file) | ||
self.parent_dir = os.path.dirname(self.base_dir) | ||
|
||
def __repr__(self): | ||
return "<Console output: %s>" % self.file | ||
|
||
def __str__(self): | ||
if not os.path.isfile(self.file): | ||
return "" | ||
|
||
try: | ||
with open(self.file, 'r') as f: | ||
return f.read() | ||
except IOError: | ||
logger.warn("Cannot read console file: %s" % self.file) | ||
return "" | ||
|
||
def __add__(self, other): | ||
self.append(other) | ||
return self | ||
|
||
def output(self): | ||
return str(self) | ||
|
||
def append(self, text): | ||
if os.path.isdir(self.parent_dir): | ||
# Write | ||
if not os.path.isdir(self.base_dir): | ||
os.makedirs(self.base_dir, exist_ok=True) | ||
|
||
with open(self.file, "a") as f: | ||
f.write(text) | ||
|
||
def reset(self, text = ""): | ||
if os.path.isdir(self.parent_dir): | ||
if not os.path.isdir(self.base_dir): | ||
os.makedirs(self.base_dir, exist_ok=True) | ||
|
||
with open(self.file, "w") as f: | ||
f.write(text) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Generated by Django 2.2.27 on 2023-09-11 19:11 | ||
import os | ||
from django.db import migrations | ||
from webodm import settings | ||
|
||
def data_path(project_id, task_id, *args): | ||
return os.path.join(settings.MEDIA_ROOT, | ||
"project", | ||
str(project_id), | ||
"task", | ||
str(task_id), | ||
"data", | ||
*args) | ||
|
||
def dump_console_outputs(apps, schema_editor): | ||
Task = apps.get_model('app', 'Task') | ||
|
||
for t in Task.objects.all(): | ||
if t.console_output is not None and len(t.console_output) > 0: | ||
dp = data_path(t.project.id, t.id) | ||
os.makedirs(dp, exist_ok=True) | ||
outfile = os.path.join(dp, "console_output.txt") | ||
|
||
with open(outfile, "w") as f: | ||
f.write(t.console_output) | ||
print("Wrote console output for %s to %s" % (t, outfile)) | ||
else: | ||
print("No task output for %s" % t) | ||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('app', '0037_profile'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(dump_console_outputs), | ||
migrations.RemoveField( | ||
model_name='task', | ||
name='console_output', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters