removed old unused code and few methods were renamed so their name better capture what they do

This commit is contained in:
Jakub Trllo 2019-01-21 14:20:36 +01:00
parent d402314eaf
commit 440f39d06f
2 changed files with 14 additions and 125 deletions

View file

@ -4,7 +4,7 @@ from pype import lib
from pype.lib import get_avalon_database
from avalon import schema
from bson.objectid import ObjectId
from pype.ftrack.ftrack_utils import ftrack_utils
from . import ftrack_utils
from avalon.vendor import jsonschema
from app.api import Logger
ValidationError = jsonschema.ValidationError
@ -50,7 +50,7 @@ def import_to_avalon(
if entity_type in ['Project']:
type = 'project'
config = ftrack_utils.get_config(entity)
config = ftrack_utils.get_project_config(entity)
schema.validate(config)
av_project_code = None

View file

@ -1,18 +1,24 @@
import os
import json
from pype import lib
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_config_data():
def get_presets_path():
templates = os.environ['PYPE_STUDIO_TEMPLATES']
path_items = [templates, 'presets', 'ftrack', 'ftrack_config.json']
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:
@ -66,7 +72,7 @@ def avalon_check_name(entity, inSchema=None):
raise ValueError(msg.format(name))
def get_apps(entity):
def get_project_apps(entity):
""" Get apps from project
Requirements:
'Entity' MUST be object of ftrack entity with entity_type 'Project'
@ -89,128 +95,11 @@ def get_apps(entity):
return apps
def get_config(entity):
def get_project_config(entity):
config = {}
config['schema'] = lib.get_avalon_project_config_schema()
config['tasks'] = [{'name': ''}]
config['apps'] = get_apps(entity)
config['apps'] = get_project_apps(entity)
config['template'] = lib.get_avalon_project_template()
return config
def get_context(entity):
parents = []
item = entity
while True:
item = item['parent']
if not item:
break
parents.append(item)
ctx = collections.OrderedDict()
folder_counter = 0
entityDic = {
'name': entity['name'],
'id': entity['id'],
}
try:
entityDic['type'] = entity['type']['name']
except Exception:
pass
ctx[entity['object_type']['name']] = entityDic
# add all parents to the context
for parent in parents:
tempdic = {}
if not parent.get('project_schema'):
tempdic = {
'name': parent['name'],
'id': parent['id'],
}
object_type = parent['object_type']['name']
if object_type == 'Folder':
object_type = object_type + str(folder_counter)
folder_counter += 1
ctx[object_type] = tempdic
# add project to the context
project = entity['project']
ctx['Project'] = {
'name': project['full_name'],
'code': project['name'],
'id': project['id'],
'root': project['root']
}
return ctx
def get_status_by_name(name):
statuses = ftrack.getTaskStatuses()
result = None
for s in statuses:
if s.get('name').lower() == name.lower():
result = s
return result
def sort_types(types):
data = {}
for t in types:
data[t] = t.get('sort')
data = sorted(data.items(), key=operator.itemgetter(1))
results = []
for item in data:
results.append(item[0])
return results
def get_next_task(task):
shot = task.getParent()
tasks = shot.getTasks()
types_sorted = sort_types(ftrack.getTaskTypes())
next_types = None
for t in types_sorted:
if t.get('typeid') == task.get('typeid'):
try:
next_types = types_sorted[(types_sorted.index(t) + 1):]
except Exception:
pass
for nt in next_types:
for t in tasks:
if nt.get('typeid') == t.get('typeid'):
return t
return None
def get_latest_version(versions):
latestVersion = None
if len(versions) > 0:
versionNumber = 0
for item in versions:
if item.get('version') > versionNumber:
versionNumber = item.getVersion()
latestVersion = item
return latestVersion
def get_thumbnail_recursive(task):
if task.get('thumbid'):
thumbid = task.get('thumbid')
return ftrack.Attachment(id=thumbid)
if not task.get('thumbid'):
parent = ftrack.Task(id=task.get('parent_id'))
return get_thumbnail_recursive(parent)