# HG changeset patch # User ymh # Date 1529659997 -7200 # Node ID 59d7cb99f4df41915a7de4ec137973c484df74b6 # Parent 1db91b73574380f4b2a0f85c8c3f18c007ad1f4f small import image correction. Check the target dir diff -r 1db91b735743 -r 59d7cb99f4df sbin/sync/config.py.tmpl --- a/sbin/sync/config.py.tmpl Tue Jun 19 17:56:58 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,75 +0,0 @@ -from fabric.api import env -from random import choice - -env.hosts = ['@'] - -env.web_group = 'iri' -env.folders = ['log', 'static/media'] - -env.repos = {'iconolab' : {'repo':"", 'src_root':'src', 'requirements': 'requirements/prod.txt', 'python_version': '3.5'}} -env.base_export_path = "/tmp" -env.export_prefix = "iconolab" -env.key = 'iconolab' - -env.remote_path = { - 'web':"/etc/www/iconolab/", - 'src':"/etc/www/iconolab", - 'virtualenv':"/srv/virtualenv/iconolab", - 'build_export':"/tmp/build", - 'pythonpath' : ['/etc/www/iconolab'] -} - -#env.remote_path = { -# 'web':"/var/www/iconolab/", -# 'src':"/Users/ymh/dev/tmp/testfab/src", -# 'virtualenv':"/Users/ymh/dev/tmp/testiconolab/virtualenv/iconolab", -# 'build_export':"/tmp/build", -# 'pythonpath' : ['/etc/www/iconolab'] -#} - - -env.platform_web_module = "iconolab" -env.remote_baseline_venv = "" - -env.rsync_filters = { - 'src' : [ - "P .htpasswd", - "P .htaccess", - "P egonomy/config.py", - ], - 'web': [ - "+ core", - "P .htpasswd", - "P .htaccess", - "P robots.txt", - "P env/***", - "P log/***", - "P index/***", - "P static/media/***", - "P crossdomain.xml", - ], - 'venv': [ - "+ core", - ] -} -env.web_relaunch_cmd = "supervisorctl restart iconolab" -env.settings = "iconolab_settings" -env.admin_cmd = "django-admin" -env.check_folder_access = False - -env.config = { - 'web': { - 'base_url': "/", - 'web_url': 'http://egonomy.iri-resesarch.org', - 'db_engine':'postgresql_psycopg2', - 'db_name':'platform', - 'db_user': 'iriuser', - 'db_password': '', - 'db_host': 'sql.iri.centrepompidou.fr', - 'db_port': 5432, - 'haystack_url' : 'http://localhost:9200', - 'haystack_index' : 'egonomy', - 'log_file' : env.remote_path['web'] + '/log/log.txt', - 'secret_key' : ''.join([choice('abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)') for i in range(50)]), - }, -} diff -r 1db91b735743 -r 59d7cb99f4df sbin/sync/fabfile.py --- a/sbin/sync/fabfile.py Tue Jun 19 17:56:58 2018 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -import imp -import os.path -import StringIO - -import config # @UnusedImport -from fablib import (export_version, do_sync_web, create_config, - clean_export_folder, do_sync_comp, sync_install_build, do_create_virtualenv, - clean_rsync_folder, rsync_export, get_src_version, sync_build, - do_relaunch_server, install_build, do_create_virtualenv_requirement, build_src) -from fabric.api import task, env, run, cd, put -from fabric.colors import green - -env.use_ssh_config = True - -def build_source(version): - print(green("build source with version %s" % version)) - export_path = export_version(iconolab=version) - export_path_full = os.path.join(export_path, env.key, env.repos[env.key]['src_root']) - build_src(export_path_full) - (_,version_str) = get_src_version(env.key, export_path_full) - return os.path.join(export_path_full,"dist","%s-%s.tar.gz" % (env.key,version_str)) - -def do_create_virtualenv(remote_build_folder): - requirements_path = os.path.join(remote_build_folder, env.repos[env.key]['requirements']) - do_create_virtualenv_requirement(requirements_path, env.remote_path['virtualenv'], env.repos[env.key]['python_version']) - # add setting path to virtualenv - ext_path = "import sys; sys.__plen = len(sys.path)\n" - for l in env.remote_path.get('pythonpath', []): - ext_path += l + "\n" - ext_path += "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" - put(StringIO.StringIO(ext_path), os.path.join(env.remote_path['virtualenv'], 'lib/python%s/site-packages/_virtualenv_path_extensions.pth'%env.repos[env.key]['python_version'])) - -@task -def relaunch_server(do_collectstatic=True, do_migrate=True, do_check_folder_access=False): - print("Relaunch server") - do_relaunch_server(do_collectstatic, do_migrate, env.get('check_folder_access',do_check_folder_access)) - -@task -def sync_site(version): - print(green("sync site and rebuild virtualenv with version %s" % version)) - build_path = build_source(version) - run('mkdir -p "%s"' % env.remote_path['build_export']) - res_trans = sync_build(build_path) - # untar build - with cd(env.remote_path['build_export']): - run('tar zxf %s' % res_trans[0]) - - do_create_virtualenv(res_trans[0][0:-7]) - - # install build - install_build(res_trans[0], env.remote_path['virtualenv']) - - # remove build + untared folder - run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7])) - clean_export_folder(env.remote_path['build_export']) - relaunch_server() - -@task -def create_virtualenv(version): - build_path = build_source(version) - run('mkdir -p "%s"' % env.remote_path['build_export']) - res_trans = sync_build(build_path) - # untar build - with cd(env.remote_path['build_export']): - run('tar zxf %s' % res_trans[0]) - - do_create_virtualenv(res_trans[0][0:-7]) - - run('rm -fr "%s" "%s" ' % (res_trans[0], res_trans[0][0:-7])) - clean_export_folder(env.remote_path['build_export']) - -@task -def sync_site_module(version): - print(green("sync site with version %s" % version)) - build_path = build_source(version) - run('mkdir -p "%s"' % env.remote_path['build_export']) - res_trans = sync_build(build_path) - # install build - install_build(res_trans[0], env.remote_path['virtualenv'], env.platform_web_module) - - # remove build + untared folder - run('rm -fr "%s"' % (res_trans[0])) - clean_export_folder(env.remote_path['build_export']) - relaunch_server() diff -r 1db91b735743 -r 59d7cb99f4df src/iconolab/management/commands/importimages.py --- a/src/iconolab/management/commands/importimages.py Tue Jun 19 17:56:58 2018 +0200 +++ b/src/iconolab/management/commands/importimages.py Fri Jun 22 11:33:17 2018 +0200 @@ -3,7 +3,7 @@ import shutil from django.conf import settings -from django.core.management.base import BaseCommand +from django.core.management.base import BaseCommand, CommandError from PIL import Image as ImagePIL from sorl.thumbnail import get_thumbnail @@ -22,9 +22,13 @@ metadata_dict, image_files, options, - source_dir, - target_dir + source_dir ): + + target_dir = os.path.join(settings.MEDIA_ROOT, Image.media.field.upload_to) + if not os.path.isdir(target_dir): + raise CommandError("Image target dir does not exists : %s" % target_dir) + print('#### Creating item '+natural_key+' (natural key) in database') item_object = Item.objects.create( collection=collection diff -r 1db91b735743 -r 59d7cb99f4df src/iconolab/models.py --- a/src/iconolab/models.py Tue Jun 19 17:56:58 2018 +0200 +++ b/src/iconolab/models.py Fri Jun 22 11:33:17 2018 +0200 @@ -1,16 +1,13 @@ import json import logging import re -import urllib import uuid import requests from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.fields import GenericRelation -from django.contrib.contenttypes.models import ContentType -from django.db import connection, models, transaction -from django.db.models import Count +from django.db import models, transaction from django.utils.functional import cached_property from django.utils.text import slugify from django_comments_xtd.models import XtdComment @@ -61,7 +58,7 @@ def completed_percent(self): items_with_annotation = \ - ImageStats.objects.filter(image__item__collection = self, annotations_count__gt=0)\ + ImageStats.objects.filter(image__item__collection=self, annotations_count__gt=0)\ .values('image__item').distinct().count() total_items = self.items_count @@ -455,7 +452,7 @@ def latest_revision_for_user(self, user): user_revisions = self.revisions.filter(creator=user) if user_revisions.exists(): - return user_revisions.filter(creator=author).order_by("-created").first() + return user_revisions.order_by("-created").first() return None @transaction.atomic