From c7e92e31d7d706982d6b8653475b23920428a117 Mon Sep 17 00:00:00 2001 From: Cyprien Caillot Date: Wed, 11 Oct 2023 22:08:51 +0200 Subject: [PATCH] add integrate_version_to_task.py --- .../publish/integrate_version_to_task.py | 65 +++++++++++++++---- 1 file changed, 53 insertions(+), 12 deletions(-) diff --git a/quad_pyblish_module/plugins/hiero/publish/integrate_version_to_task.py b/quad_pyblish_module/plugins/hiero/publish/integrate_version_to_task.py index 270270e..278e8ff 100644 --- a/quad_pyblish_module/plugins/hiero/publish/integrate_version_to_task.py +++ b/quad_pyblish_module/plugins/hiero/publish/integrate_version_to_task.py @@ -1,4 +1,4 @@ -import pyblish import api +from pyblish import api class IntegrateVersionToTask(api.ContextPlugin): @@ -6,18 +6,59 @@ class IntegrateVersionToTask(api.ContextPlugin): order = api.IntegratorOrder + 10.1 hosts = ["hiero"] + families = ["clip"] label = "Integrate Version To Task" optional = False + def get_all_task_types(self, project): + tasks = {} + proj_template = project['project_schema'] + temp_task_types = proj_template['_task_type_schema']['types'] + + for type in temp_task_types: + if type['name'] not in tasks: + tasks[type['name']] = type + + return tasks + def process(self, context): - print('----------------------------------------') - print('----------------------------------------') - print('----------------------------------------') - print('----------------------------------------') - from pprint import pprint - print(type(context)) - pprint(context.data) - print('----------------------------------------') - print('----------------------------------------') - print('----------------------------------------') - print('----------------------------------------') + # Get Usefull Data + task_type = context.data.get('task').lower() + ftrack_session = context.data.get('ftrackSession') + ftrack_project = context.data.get('ftrackProject') + ftrack_task_types = self.get_all_task_types(ftrack_project) + + if ftrack_session is None: + self.log.info('Ftrack session is not created.') + return + + to_analyze_lst = [] + for result_dict in context.data.get('results'): + if 'Collect OTIO Review' in result_dict['plugin'].label: + to_analyze_lst.append(result_dict) + + for to_analyze in to_analyze_lst: + ftrack_shot_version = to_analyze['instance'].data['ftrackEntity'] + ftrack_asset_versions = to_analyze['instance'].data['ftrackIntegratedAssetVersions'] + + # Check if confo task already exists in ftrack + is_task_exist = ftrack_session.query('Task where name is "{0}" and parent.id is {1}'.format(task_type, ftrack_shot_version['id'])).first() + if not is_task_exist: + new_task = ftrack_session.create( + 'Task', + { + 'name': task_type, + 'parent': ftrack_shot_version, + 'type': ftrack_task_types[task_type] + } + ) + else: + new_task = is_task_exist + + ftrack_session.commit() + + # Link Publish version to Task + for asset_version in ftrack_asset_versions: + asset_version['task'] = new_task + + ftrack_session.commit() \ No newline at end of file