kopia lustrzana https://github.com/OpenDroneMap/WebODM
Link task_output.txt <==> console_output.txt
rodzic
4678a21ead
commit
30684f4440
|
|
@ -46,6 +46,9 @@ class Console:
|
||||||
try:
|
try:
|
||||||
if not os.path.isdir(self.base_dir):
|
if not os.path.isdir(self.base_dir):
|
||||||
os.makedirs(self.base_dir, exist_ok=True)
|
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:
|
with open(self.file, "w", encoding="utf-8") as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
|
|
@ -61,4 +64,16 @@ class Console:
|
||||||
with open(self.file, "w", encoding="utf-8") as f:
|
with open(self.file, "w", encoding="utf-8") as f:
|
||||||
f.write(text)
|
f.write(text)
|
||||||
except OSError:
|
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))
|
||||||
|
|
@ -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),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
@ -480,9 +480,6 @@ class Task(models.Model):
|
||||||
try:
|
try:
|
||||||
# Try to use hard links first
|
# Try to use hard links first
|
||||||
shutil.copytree(self.task_path(), task.task_path(), copy_function=os.link)
|
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:
|
except Exception as e:
|
||||||
logger.warning("Cannot duplicate task using hard links, will use normal copy instead: {}".format(str(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())
|
shutil.copytree(self.task_path(), task.task_path())
|
||||||
|
|
@ -1048,6 +1045,11 @@ class Task(models.Model):
|
||||||
self.import_url = ""
|
self.import_url = ""
|
||||||
else:
|
else:
|
||||||
self.console += gettext("Done!") + "\n"
|
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()
|
self.save()
|
||||||
|
|
||||||
|
|
|
||||||
Ładowanie…
Reference in New Issue