2017-07-07 19:34:02 +00:00
# -*- 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
2017-07-12 12:56:43 +00:00
import os
2017-07-07 19:34:02 +00:00
from django . db import migrations , models
2017-07-12 12:56:43 +00:00
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 ' ) ,
2018-09-04 22:46:07 +00:00
' orthophoto.mbtiles ' : os . path . join ( ' odm_orthophoto ' , ' odm_orthophoto.mbtiles ' ) ,
2017-07-12 12:56:43 +00:00
' georeferenced_model.las ' : os . path . join ( ' odm_georeferencing ' , ' odm_georeferenced_model.las ' ) ,
2018-06-22 20:23:31 +00:00
' georeferenced_model.laz ' : os . path . join ( ' odm_georeferencing ' , ' odm_georeferenced_model.laz ' ) ,
2017-07-12 12:56:43 +00:00
' 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 '
}
}
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
2017-07-07 19:34:02 +00:00
def detect_available_assets ( apps , schema_editor ) :
2017-07-10 14:30:33 +00:00
Task = apps . get_model ( ' app ' , ' Task ' )
2017-07-07 19:34:02 +00:00
for t in Task . objects . all ( ) :
print ( " Updating {} " . format ( t ) )
2017-07-12 12:56:43 +00:00
all_assets = list ( ASSETS_MAP . keys ( ) )
t . available_assets = [ asset for asset in all_assets if is_asset_available_slow ( t , asset ) ]
t . save ( )
2017-07-07 19:34:02 +00:00
class Migration ( migrations . Migration ) :
dependencies = [
( ' app ' , ' 0005_auto_20170707_1014 ' ) ,
]
operations = [
migrations . AddField (
model_name = ' task ' ,
name = ' available_assets ' ,
field = django . contrib . postgres . fields . ArrayField ( base_field = models . CharField ( max_length = 80 ) , blank = True , default = [ ] , help_text = ' List of available assets to download ' , size = None ) ,
) ,
migrations . RunPython ( detect_available_assets ) ,
]