mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
Silo is set to same name as highest parent, except Project
This commit is contained in:
parent
476208b1e2
commit
91c3bbf022
2 changed files with 69 additions and 66 deletions
|
|
@ -151,66 +151,6 @@ class SyncToAvalon(BaseAction):
|
|||
for child in childrens:
|
||||
self.getShotAsset(child)
|
||||
|
||||
def getData(self, entity, session):
|
||||
entity_type = entity.entity_type
|
||||
|
||||
data = {}
|
||||
data['ftrackId'] = entity['id']
|
||||
data['entityType'] = entity_type
|
||||
|
||||
for cust_attr in self.custom_attributes:
|
||||
key = cust_attr['key']
|
||||
if cust_attr['entity_type'].lower() in ['asset']:
|
||||
data[key] = entity['custom_attributes'][key]
|
||||
|
||||
elif cust_attr['entity_type'].lower() in ['show'] and entity_type.lower() == 'project':
|
||||
data[key] = entity['custom_attributes'][key]
|
||||
|
||||
elif cust_attr['entity_type'].lower() in ['task'] and entity_type.lower() != 'project':
|
||||
# Put space between capitals (e.g. 'AssetBuild' -> 'Asset Build')
|
||||
entity_type_full = re.sub(r"(\w)([A-Z])", r"\1 \2", entity_type)
|
||||
# Get object id of entity type
|
||||
ent_obj_type_id = session.query('ObjectType where name is "{}"'.format(entity_type_full)).one()['id']
|
||||
|
||||
if cust_attr['object_type_id'] == ent_obj_type_id:
|
||||
data[key] = entity['custom_attributes'][key]
|
||||
|
||||
if entity_type in ['Project']:
|
||||
data['code'] = entity['name']
|
||||
return data
|
||||
|
||||
# Get info for 'Data' in Avalon DB
|
||||
tasks = []
|
||||
for child in entity['children']:
|
||||
if child.entity_type in ['Task']:
|
||||
tasks.append(child['name'])
|
||||
|
||||
# Get list of parents without project
|
||||
parents = []
|
||||
for i in range(1, len(entity['link'])-1):
|
||||
tmp = session.get(entity['link'][i]['type'], entity['link'][i]['id'])
|
||||
parents.append(tmp)
|
||||
|
||||
folderStruct = []
|
||||
parentId = None
|
||||
|
||||
for parent in parents:
|
||||
parName = parent['name']
|
||||
folderStruct.append(parName)
|
||||
parentId = io.find_one({'type': 'asset', 'name': parName})['_id']
|
||||
if parent['parent'].entity_type != 'project' and parentId is None:
|
||||
self.importToAvalon(parent)
|
||||
parentId = io.find_one({'type': 'asset', 'name': parName})['_id']
|
||||
|
||||
hierarchy = os.path.sep.join(folderStruct)
|
||||
|
||||
data['visualParent'] = parentId
|
||||
data['parents'] = folderStruct
|
||||
data['tasks'] = tasks
|
||||
data['hierarchy'] = hierarchy
|
||||
|
||||
return data
|
||||
|
||||
def importToAvalon(self, session, entity):
|
||||
# --- Begin: PUSH TO Avalon ---
|
||||
|
||||
|
|
@ -240,7 +180,7 @@ class SyncToAvalon(BaseAction):
|
|||
elif self.avalon_project['name'] != entity['full_name']:
|
||||
raise ValueError('You can\'t change name {} to {}, avalon DB won\'t work properly!'.format(avalon_asset['name'], name))
|
||||
|
||||
data = self.getData(entity, session)
|
||||
data = ftrack_utils.get_data(self, entity, session,self.custom_attributes)
|
||||
|
||||
# Store info about project (FtrackId)
|
||||
io.update_many({
|
||||
|
|
@ -259,17 +199,14 @@ class SyncToAvalon(BaseAction):
|
|||
|
||||
## ----- ASSETS ------
|
||||
# Presets:
|
||||
# TODO how to check if entity is Asset Library or AssetBuild?
|
||||
silo = 'Film'
|
||||
if entity_type in ['AssetBuild', 'Library']:
|
||||
silo = 'Assets'
|
||||
|
||||
data = ftrack_utils.get_data(self, entity, session, self.custom_attributes)
|
||||
silo = data.pop('silo')
|
||||
os.environ['AVALON_SILO'] = silo
|
||||
|
||||
name = entity['name']
|
||||
os.environ['AVALON_ASSET'] = name
|
||||
|
||||
data = self.getData(entity, session)
|
||||
|
||||
# Try to find asset in current database
|
||||
avalon_asset = None
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import sys
|
||||
import re
|
||||
from pprint import *
|
||||
|
||||
import ftrack_api
|
||||
|
|
@ -12,6 +13,71 @@ from app.api import Logger
|
|||
|
||||
log = Logger.getLogger(__name__)
|
||||
|
||||
def get_data(parent, entity, session, custom_attributes):
|
||||
entity_type = entity.entity_type
|
||||
|
||||
data = {}
|
||||
data['ftrackId'] = entity['id']
|
||||
data['entityType'] = entity_type
|
||||
|
||||
for cust_attr in custom_attributes:
|
||||
key = cust_attr['key']
|
||||
if cust_attr['entity_type'].lower() in ['asset']:
|
||||
data[key] = entity['custom_attributes'][key]
|
||||
|
||||
elif cust_attr['entity_type'].lower() in ['show'] and entity_type.lower() == 'project':
|
||||
data[key] = entity['custom_attributes'][key]
|
||||
|
||||
elif cust_attr['entity_type'].lower() in ['task'] and entity_type.lower() != 'project':
|
||||
# Put space between capitals (e.g. 'AssetBuild' -> 'Asset Build')
|
||||
entity_type_full = re.sub(r"(\w)([A-Z])", r"\1 \2", entity_type)
|
||||
# Get object id of entity type
|
||||
ent_obj_type_id = session.query('ObjectType where name is "{}"'.format(entity_type_full)).one()['id']
|
||||
|
||||
if cust_attr['object_type_id'] == ent_obj_type_id:
|
||||
data[key] = entity['custom_attributes'][key]
|
||||
|
||||
if entity_type in ['Project']:
|
||||
data['code'] = entity['name']
|
||||
return data
|
||||
|
||||
# Get info for 'Data' in Avalon DB
|
||||
tasks = []
|
||||
for child in entity['children']:
|
||||
if child.entity_type in ['Task']:
|
||||
tasks.append(child['name'])
|
||||
|
||||
# Get list of parents without project
|
||||
parents = []
|
||||
for i in range(1, len(entity['link'])-1):
|
||||
tmp = session.get(entity['link'][i]['type'], entity['link'][i]['id'])
|
||||
parents.append(tmp)
|
||||
|
||||
silo = entity['name']
|
||||
if len(parents) > 0:
|
||||
silo = parents[0]['name']
|
||||
|
||||
folderStruct = []
|
||||
parentId = None
|
||||
|
||||
for parent in parents:
|
||||
parName = parent['name']
|
||||
folderStruct.append(parName)
|
||||
parentId = io.find_one({'type': 'asset', 'name': parName})['_id']
|
||||
if parent['parent'].entity_type != 'project' and parentId is None:
|
||||
parent.importToAvalon(parent)
|
||||
parentId = io.find_one({'type': 'asset', 'name': parName})['_id']
|
||||
|
||||
hierarchy = os.path.sep.join(folderStruct)
|
||||
|
||||
data['silo'] = silo
|
||||
data['visualParent'] = parentId
|
||||
data['parents'] = folderStruct
|
||||
data['tasks'] = tasks
|
||||
data['hierarchy'] = hierarchy
|
||||
|
||||
return data
|
||||
|
||||
def avalon_check_name(entity, inSchema = None):
|
||||
alright = True
|
||||
name = entity['name']
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue