From 6e62d9c2a6d55244677317a8776a352cfd500089 Mon Sep 17 00:00:00 2001 From: Francesco Siddi Date: Wed, 28 Oct 2015 15:34:23 +0100 Subject: [PATCH] Tweaks to import code This can be phased out later, since we will not need to import more projects from the old cloud. --- pillar/manage.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/pillar/manage.py b/pillar/manage.py index 6785401b..9133b99f 100644 --- a/pillar/manage.py +++ b/pillar/manage.py @@ -1104,7 +1104,9 @@ def import_data(path): @manager.command def make_thumbnails(): + from bson.objectid import ObjectId from application.modules.file_storage import build_thumbnails + import shutil files = db.files.find() for f in files: if f['content_type'].split('/')[0] == 'image': @@ -1112,10 +1114,38 @@ def make_thumbnails(): if '-' in f['path']: pass #print "Skipping {0}".format(f['path']) + elif f['backend'] == 'pillar': + a = db.files.find({'parent': ObjectId(f['_id'])}) + a_count = 0 + for b in a: + a_count += 1 + if a_count == 0: + file_path = f['path'] + print "Building {0}".format(file_path) + file_full_path = os.path.join( + app.config['STORAGE_DIR'], file_path) + if not os.path.exists(file_full_path): + src_shared_full_path = os.path.join( + app.config['SHARED_DIR'], 'files', file_path[3:]) + print src_shared_full_path + + dst_root_dir = os.path.join( + app.config['STORAGE_DIR'], file_path[:3]) + dst_file_full_path_ = os.path.join( + app.config['STORAGE_DIR'], file_path) + if not os.path.exists(dst_root_dir): + os.makedirs(dst_root_dir) + shutil.copy(src_shared_full_path, + dst_file_full_path_) + print dst_file_full_path_ + else: + t = build_thumbnails(file_path=file_path) + print t + + #t = build_thumbnails(file_path=f['path']) + #print t else: - print "Building {0}".format(f['path']) - t = build_thumbnails(file_path=f['path']) - print t + pass @manager.command def add_node_permissions():