zhongrj
2025-11-25 b89962006164a462404b79a738bee8cbb6d7fe7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-07-07 18:05
from __future__ import unicode_literals
 
import django.contrib.postgres.fields
import os
from django.db import migrations, models
 
from webodm import settings
 
ASSETS_MAP = {
    'all.zip': 'all.zip',
    'orthophoto.tif': os.path.join('odm_orthophoto', 'odm_orthophoto.tif'),
    'orthophoto.png': os.path.join('odm_orthophoto', 'odm_orthophoto.png'),
    'orthophoto.mbtiles': os.path.join('odm_orthophoto', 'odm_orthophoto.mbtiles'),
    'georeferenced_model.las': os.path.join('odm_georeferencing', 'odm_georeferenced_model.las'),
    'georeferenced_model.laz': os.path.join('odm_georeferencing', 'odm_georeferenced_model.laz'),
    'georeferenced_model.ply': os.path.join('odm_georeferencing', 'odm_georeferenced_model.ply'),
    'georeferenced_model.csv': os.path.join('odm_georeferencing', 'odm_georeferenced_model.csv'),
    'textured_model.zip': {
        'deferred_path': 'textured_model.zip',
        'deferred_compress_dir': 'odm_texturing'
    },
    'dtm.tif': os.path.join('odm_dem', 'dtm.tif'),
    'dsm.tif': os.path.join('odm_dem', 'dsm.tif'),
    'dtm_tiles.zip': {
        'deferred_path': 'dtm_tiles.zip',
        'deferred_compress_dir': 'dtm_tiles'
    },
    'dsm_tiles.zip': {
        'deferred_path': 'dsm_tiles.zip',
        'deferred_compress_dir': 'dsm_tiles'
    },
    'orthophoto_tiles.zip': {
        'deferred_path': 'orthophoto_tiles.zip',
        'deferred_compress_dir': 'orthophoto_tiles'
    },
}
 
def assets_path(project_id, task_id, *args):
    return os.path.join(settings.MEDIA_ROOT,
                        "project",
                        str(project_id),
                        "task",
                        str(task_id),
                        "assets",
                        *args)
 
def is_asset_available_slow(t, asset):
    if asset in ASSETS_MAP:
        value = ASSETS_MAP[asset]
        if isinstance(value, str):
            return os.path.exists(assets_path(t.project.id, t.id, value))
        elif isinstance(value, dict):
            if 'deferred_compress_dir' in value:
                return os.path.exists(assets_path(t.project.id, t.id, value['deferred_compress_dir']))
 
    return False
 
 
def detect_available_assets(apps, schema_editor):
    Task = apps.get_model('app', 'Task')
 
    for t in Task.objects.all():
        print("Updating {}".format(t))
 
        all_assets = list(ASSETS_MAP.keys())
        t.available_assets = [asset for asset in all_assets if is_asset_available_slow(t, asset)]
        t.save()
 
 
class Migration(migrations.Migration):
 
    dependencies = [
        ('app', '0023_task_running_progress'),
    ]
 
    operations = [
        migrations.RunPython(detect_available_assets),
    ]