Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Ftrack integrate hierarchy fix #1085

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 67 additions & 12 deletions pype/plugins/ftrack/publish/integrate_hierarchy_ftrack.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
import sys
import collections
import six

import pyblish.api
from avalon import io

try:
from pype.modules.ftrack.lib.avalon_sync import CUST_ATTR_AUTO_SYNC
except Exception:
CUST_ATTR_AUTO_SYNC = "avalon_auto_sync"
# Copy of constant `pype.modules.ftrack.lib.avalon_sync.CUST_ATTR_AUTO_SYNC`
CUST_ATTR_AUTO_SYNC = "avalon_auto_sync"


# Copy of `get_pype_attr` from pype.modules.ftrack.lib
def get_pype_attr(session, split_hierarchical=True):
custom_attributes = []
hier_custom_attributes = []
# TODO remove deprecated "avalon" group from query
cust_attrs_query = (
"select id, entity_type, object_type_id, is_hierarchical, default"
" from CustomAttributeConfiguration"
" where group.name in (\"avalon\", \"pype\")"
)
all_avalon_attr = session.query(cust_attrs_query).all()
for cust_attr in all_avalon_attr:
if split_hierarchical and cust_attr["is_hierarchical"]:
hier_custom_attributes.append(cust_attr)
continue

custom_attributes.append(cust_attr)

if split_hierarchical:
# return tuple
return custom_attributes, hier_custom_attributes

return custom_attributes


class IntegrateHierarchyToFtrack(pyblish.api.ContextPlugin):
Expand Down Expand Up @@ -36,7 +61,7 @@ class IntegrateHierarchyToFtrack(pyblish.api.ContextPlugin):
order = pyblish.api.IntegratorOrder - 0.04
label = 'Integrate Hierarchy To Ftrack'
families = ["shot"]
hosts = ["hiero"]
hosts = ["hiero", "standalonepublisher"]
optional = False

def process(self, context):
Expand All @@ -50,8 +75,7 @@ def process(self, context):
project_name = self.context.data["projectEntity"]["name"]
query = 'Project where full_name is "{}"'.format(project_name)
project = self.session.query(query).one()
auto_sync_state = project[
"custom_attributes"][CUST_ATTR_AUTO_SYNC]
auto_sync_state = project["custom_attributes"][CUST_ATTR_AUTO_SYNC]

if not io.Session:
io.install()
Expand All @@ -74,6 +98,15 @@ def process(self, context):
self.auto_sync_on(project)

def import_to_ftrack(self, input_data, parent=None):
# Prequery hiearchical custom attributes
hier_custom_attributes = get_pype_attr(self.session)[1]
hier_attr_by_key = {
attr["key"]: attr
for attr in hier_custom_attributes
}
# Get ftrack api module (as they are different per python version)
ftrack_api = self.context.data["ftrackPythonModule"]

for entity_name in input_data:
entity_data = input_data[entity_name]
entity_type = entity_data['entity_type']
Expand Down Expand Up @@ -116,12 +149,34 @@ def import_to_ftrack(self, input_data, parent=None):
i for i in self.context if i.data['asset'] in entity['name']
]
for key in custom_attributes:
assert (key in entity['custom_attributes']), (
'Missing custom attribute key: `{0}` in attrs: '
'`{1}`'.format(key, entity['custom_attributes'].keys())
)
hier_attr = hier_attr_by_key.get(key)
# Use simple method if key is not hierarchical
if not hier_attr:
assert (key in entity['custom_attributes']), (
'Missing custom attribute key: `{0}` in attrs: '
'`{1}`'.format(key, entity['custom_attributes'].keys())
)

entity['custom_attributes'][key] = custom_attributes[key]
entity['custom_attributes'][key] = custom_attributes[key]

else:
# Use ftrack operations method to set hiearchical
# attribute value.
# - this is because there may be non hiearchical custom
# attributes with different properties
entity_key = collections.OrderedDict()
entity_key["configuration_id"] = hier_attr["id"]
entity_key["entity_id"] = entity["id"]

self.session.recorded_operations.push(
ftrack_api.operation.UpdateEntityOperation(
"ContextCustomAttributeValue",
entity_key,
"value",
ftrack_api.symbol.NOT_SET,
custom_attributes[key]
)
)

for instance in instances:
instance.data['ftrackEntity'] = entity
Expand Down
Loading