Link task_output.txt <==> console_output.txt

pull/1662/head
Piero Toffanin 2025-05-05 03:06:25 -04:00
rodzic 4678a21ead
commit 30684f4440
3 zmienionych plików z 56 dodań i 4 usunięć

Wyświetl plik

@ -46,6 +46,9 @@ class Console:
try:
if not os.path.isdir(self.base_dir):
os.makedirs(self.base_dir, exist_ok=True)
if os.path.isfile(self.file):
os.unlink(self.file)
with open(self.file, "w", encoding="utf-8") as f:
f.write(text)
@ -61,4 +64,16 @@ class Console:
with open(self.file, "w", encoding="utf-8") as f:
f.write(text)
except OSError:
logger.warn("Cannot delink console file: %s" % self.file)
logger.warn("Cannot delink console file: %s" % self.file)
def link(self, src_file):
try:
if not os.path.isfile(src_file):
raise OSError("Source file does not exist")
if os.path.isfile(self.file):
os.unlink(self.file)
os.link(src_file, self.file)
except OSError:
logger.warn("Cannot link console file: %s --> %s" % (src_file, self.file))

Wyświetl plik

@ -0,0 +1,35 @@
# Generated by Django 2.2.27 on 2025-05-02 19:45
from django.db import migrations
import os
from webodm import settings
def update_task_console_link(apps, schema_editor):
Task = apps.get_model('app', 'Task')
for t in Task.objects.all():
task_output = os.path.join(settings.MEDIA_ROOT, "project", str(t.project.id), "task", str(t.id), "assets", "task_output.txt")
console_output = os.path.join(settings.MEDIA_ROOT, "project", str(t.project.id), "task", str(t.id), "data", "console_output.txt")
if os.path.isfile(task_output) and os.path.isfile(console_output):
print("Update {}".format(t))
# Guarantee consistency, save space
try:
if os.path.isfile(console_output):
os.unlink(console_output)
os.link(task_output, console_output)
except OSError:
print("Cannot link console file: %s --> %s" % (task_output, console_output))
class Migration(migrations.Migration):
dependencies = [
('app', '0043_task_crop'),
]
operations = [
migrations.RunPython(update_task_console_link),
]

Wyświetl plik

@ -480,9 +480,6 @@ class Task(models.Model):
try:
# Try to use hard links first
shutil.copytree(self.task_path(), task.task_path(), copy_function=os.link)
# Make sure the console output is not linked to the original task
task.console.delink()
except Exception as e:
logger.warning("Cannot duplicate task using hard links, will use normal copy instead: {}".format(str(e)))
shutil.copytree(self.task_path(), task.task_path())
@ -1048,6 +1045,11 @@ class Task(models.Model):
self.import_url = ""
else:
self.console += gettext("Done!") + "\n"
task_output = self.assets_path("task_output.txt")
if os.path.isfile(task_output):
# Guarantee consistency, save space
self.console.link(task_output)
self.save()