From bdec0bf8f96cf3ad097442b90a50de1bf29c141b Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Tue, 22 Jan 2019 09:54:24 +0100 Subject: [PATCH] ftrack_utils.py removed --- .../actions/action_sync_to_avalon_local.py | 5 +- pype/ftrack/ftrack_utils/avalon_sync.py | 94 +++++++++++++++- pype/ftrack/ftrack_utils/ftrack_utils.py | 105 ------------------ pype/lib.py | 7 ++ 4 files changed, 99 insertions(+), 112 deletions(-) delete mode 100644 pype/ftrack/ftrack_utils/ftrack_utils.py diff --git a/pype/ftrack/actions/action_sync_to_avalon_local.py b/pype/ftrack/actions/action_sync_to_avalon_local.py index 686bf2361a..e49328dbfd 100644 --- a/pype/ftrack/actions/action_sync_to_avalon_local.py +++ b/pype/ftrack/actions/action_sync_to_avalon_local.py @@ -3,11 +3,9 @@ import sys import argparse import logging import json -import importlib import ftrack_api -from pype.ftrack import BaseAction -from pype.ftrack import ftrack_utils +from pype.ftrack import BaseAction, ftrack_utils class SyncToAvalon(BaseAction): @@ -62,7 +60,6 @@ class SyncToAvalon(BaseAction): def __init__(self, session): super(SyncToAvalon, self).__init__(session) # reload utils on initialize (in case of server restart) - importlib.reload(ftrack_utils) def discover(self, session, entities, event): ''' Validation ''' diff --git a/pype/ftrack/ftrack_utils/avalon_sync.py b/pype/ftrack/ftrack_utils/avalon_sync.py index 931e12acf4..2f131b17fe 100644 --- a/pype/ftrack/ftrack_utils/avalon_sync.py +++ b/pype/ftrack/ftrack_utils/avalon_sync.py @@ -1,12 +1,16 @@ import os import re +import json from pype import lib from pype.lib import get_avalon_database -from avalon import schema from bson.objectid import ObjectId from . import ftrack_utils -from avalon.vendor import jsonschema +import avalon +import avalon.api +from avalon import schema +from avalon.vendor import toml, jsonschema from app.api import Logger + ValidationError = jsonschema.ValidationError log = Logger.getLogger(__name__) @@ -50,7 +54,7 @@ def import_to_avalon( if entity_type in ['Project']: type = 'project' - config = ftrack_utils.get_project_config(entity) + config = get_project_config(entity) schema.validate(config) av_project_code = None @@ -430,3 +434,87 @@ def get_avalon_project(ft_project): }) return avalon_project + + +def get_project_config(entity): + config = {} + config['schema'] = lib.get_avalon_project_config_schema() + config['tasks'] = [{'name': ''}] + config['apps'] = get_project_apps(entity) + config['template'] = lib.get_avalon_project_template() + + return config + + +def get_project_apps(entity): + """ Get apps from project + Requirements: + 'Entity' MUST be object of ftrack entity with entity_type 'Project' + Checking if app from ftrack is available in Templates/bin/{app_name}.toml + + Returns: + Array with dictionaries with app Name and Label + """ + apps = [] + for app in entity['custom_attributes']['applications']: + try: + app_config = {} + app_config['name'] = app + app_config['label'] = toml.load(avalon.lib.which_app(app))['label'] + + apps.append(app_config) + + except Exception as e: + log.warning('Error with application {0} - {1}'.format(app, e)) + return apps + + +def avalon_check_name(entity, inSchema=None): + ValidationError = jsonschema.ValidationError + alright = True + name = entity['name'] + if " " in name: + alright = False + + data = {} + data['data'] = {} + data['type'] = 'asset' + schema = "avalon-core:asset-2.0" + # TODO have project any REGEX check? + if entity.entity_type in ['Project']: + # data['type'] = 'project' + name = entity['full_name'] + # schema = get_avalon_project_template_schema() + + data['silo'] = 'Film' + + if inSchema is not None: + schema = inSchema + data['schema'] = schema + data['name'] = name + try: + avalon.schema.validate(data) + except ValidationError: + alright = False + + if alright is False: + msg = '"{}" includes unsupported symbols like "dash" or "space"' + raise ValueError(msg.format(name)) + + +def get_config_data(): + path_items = [lib.get_presets_path(), 'ftrack', 'ftrack_config.json'] + filepath = os.path.sep.join(path_items) + data = dict() + try: + with open(filepath) as data_file: + data = json.load(data_file) + + except Exception as e: + msg = ( + 'Loading "Ftrack Config file" Failed.' + ' Please check log for more information.' + ) + log.warning("{} - {}".format(msg, str(e))) + + return data diff --git a/pype/ftrack/ftrack_utils/ftrack_utils.py b/pype/ftrack/ftrack_utils/ftrack_utils.py deleted file mode 100644 index 87618b6d84..0000000000 --- a/pype/ftrack/ftrack_utils/ftrack_utils.py +++ /dev/null @@ -1,105 +0,0 @@ -import os -import json - -import avalon -import avalon.api -from avalon.vendor import toml, jsonschema -from app.api import Logger -from pype import lib - -log = Logger.getLogger(__name__) - - -def get_presets_path(): - templates = os.environ['PYPE_STUDIO_TEMPLATES'] - path_items = [templates, 'presets'] - filepath = os.path.sep.join(path_items) - return filepath - - -def get_config_data(): - path_items = [get_presets_path(), 'ftrack', 'ftrack_config.json'] - filepath = os.path.sep.join(path_items) - data = dict() - try: - with open(filepath) as data_file: - data = json.load(data_file) - - except Exception as e: - msg = ( - 'Loading "Ftrack Config file" Failed.' - ' Please check log for more information.' - ' Times are set to default.' - ) - log.warning("{} - {}".format(msg, str(e))) - - return data - - -def avalon_check_name(entity, inSchema=None): - ValidationError = jsonschema.ValidationError - alright = True - name = entity['name'] - if " " in name: - alright = False - - data = {} - data['data'] = {} - data['type'] = 'asset' - schema = "avalon-core:asset-2.0" - # TODO have project any REGEX check? - if entity.entity_type in ['Project']: - # data['type'] = 'project' - name = entity['full_name'] - # schema = get_avalon_project_template_schema() - # elif entity.entity_type in ['AssetBuild','Library']: - # data['silo'] = 'Assets' - # else: - # data['silo'] = 'Film' - data['silo'] = 'Film' - - if inSchema is not None: - schema = inSchema - data['schema'] = schema - data['name'] = name - try: - avalon.schema.validate(data) - except ValidationError: - alright = False - - if alright is False: - msg = '"{}" includes unsupported symbols like "dash" or "space"' - raise ValueError(msg.format(name)) - - -def get_project_apps(entity): - """ Get apps from project - Requirements: - 'Entity' MUST be object of ftrack entity with entity_type 'Project' - Checking if app from ftrack is available in Templates/bin/{app_name}.toml - - Returns: - Array with dictionaries with app Name and Label - """ - apps = [] - for app in entity['custom_attributes']['applications']: - try: - app_config = {} - app_config['name'] = app - app_config['label'] = toml.load(avalon.lib.which_app(app))['label'] - - apps.append(app_config) - - except Exception as e: - log.warning('Error with application {0} - {1}'.format(app, e)) - return apps - - -def get_project_config(entity): - config = {} - config['schema'] = lib.get_avalon_project_config_schema() - config['tasks'] = [{'name': ''}] - config['apps'] = get_project_apps(entity) - config['template'] = lib.get_avalon_project_template() - - return config diff --git a/pype/lib.py b/pype/lib.py index 781e665224..5fb9617eeb 100644 --- a/pype/lib.py +++ b/pype/lib.py @@ -393,3 +393,10 @@ def get_all_avalon_projects(): for name in project_names: projects.append(db[name].find_one({'type': 'project'})) return projects + + +def get_presets_path(): + templates = os.environ['PYPE_STUDIO_TEMPLATES'] + path_items = [templates, 'presets'] + filepath = os.path.sep.join(path_items) + return filepath