ftrack_utils.py removed

This commit is contained in:
Jakub Trllo 2019-01-22 09:54:24 +01:00
parent e75e331707
commit bdec0bf8f9
4 changed files with 99 additions and 112 deletions

View file

@ -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 '''

View file

@ -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

View file

@ -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

View file

@ -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