From 481646ed153afe5463aef614ff51ce372b0b2a7b Mon Sep 17 00:00:00 2001 From: infintropy <36432437+infintropy@users.noreply.github.com> Date: Mon, 18 Apr 2022 12:46:40 -0400 Subject: [PATCH 1/2] changing old approach to exception --- python/tk_multi_perforce/operations.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/python/tk_multi_perforce/operations.py b/python/tk_multi_perforce/operations.py index 7757e9b..df2bacb 100644 --- a/python/tk_multi_perforce/operations.py +++ b/python/tk_multi_perforce/operations.py @@ -15,6 +15,7 @@ import os import pprint import sys +import traceback import sgtk @@ -111,9 +112,11 @@ def open_sync_files_dialog(app, entity_type=None, entity_ids=None): try: p4_fw = sgtk.platform.get_framework("tk-framework-perforce") p4_fw.sync.sync_with_dialog(app, entities_to_sync, specific_files) - except: - app.log_exception("Failed to Open Sync dialog!") - return + except Exception: + import traceback + app.log_error("Failed to Open Sync dialog!") + app.log_error(traceback.format_exc()) + def entities_from_tasks(app, tasks): entities_to_sync = [] From 5d17db6d01e2f5b37367332cc1d2652fb087f0a6 Mon Sep 17 00:00:00 2001 From: infintropy <36432437+infintropy@users.noreply.github.com> Date: Mon, 18 Apr 2022 12:51:35 -0400 Subject: [PATCH 2/2] wrap the entire window open. This block will soon be deprecated but this is for testing --- python/tk_multi_perforce/operations.py | 109 +++++++++++++------------ 1 file changed, 55 insertions(+), 54 deletions(-) diff --git a/python/tk_multi_perforce/operations.py b/python/tk_multi_perforce/operations.py index df2bacb..5bc254a 100644 --- a/python/tk_multi_perforce/operations.py +++ b/python/tk_multi_perforce/operations.py @@ -53,63 +53,64 @@ def open_sync_files_dialog(app, entity_type=None, entity_ids=None): """ Prepare assets to send to the P4 Sync window to process """ - specific_files = False - entities_to_sync = [] - - synclog = app.engine.sgtk.synchronize_filesystem_structure() - app.log_debug(f"Synced Folders: {synclog}") - - if entity_type: - # if a single task were selected, or launched from a task detail page - if entity_type == "Task": - tasks = app.shotgun.find(entity_type, [['id', 'in', entity_ids]], ['entity']) - entities_to_sync = entities_from_tasks(app, tasks) - - # if assets were selected, make sure we have all the top level assets from child selections - elif entity_type == "Asset": - ids = [] - assets = app.shotgun.find(entity_type, [['id', 'in', entity_ids]], ['sg_asset_parent', 'code']) - parent_asset_ids = ids.extend([i.get('sg_asset_parent').get('id') for i in assets if i.get('sg_asset_parent')]) - asset_ids = ids.extend([i.get('id') for i in assets if not i.get('sg_asset_parent')]) - entities_to_sync = [{"type": entity_type, "id": id} for id in list(set(ids))] - app.log_info(entities_to_sync) - - elif entity_type == "PublishedFile": - specific_files = True - pfiles = app.shotgun.find(entity_type, [['id', 'in', entity_ids]], ['entity', 'path_cache', 'path']) - entities_to_sync = pfiles - app.log_info(entities_to_sync) - - elif entity_type == "Sequence": - ids = [] - asset_ids = [] - seqs = app.shotgun.find("Sequence", [['id', 'in', entity_ids]], ["assets"]) - for seq in seqs: - asset_ids.extend([i.get('id') for i in seq.get('assets')]) - assets = app.shotgun.find('Asset', [['id', 'in', asset_ids]], ['sg_asset_parent', 'code']) - parent_asset_ids = ids.extend([i.get('sg_asset_parent').get('id') for i in assets if i.get('sg_asset_parent')]) - asset_ids = ids.extend([i.get('id') for i in assets if not i.get('sg_asset_parent')]) - entities_to_sync = [{"type": "Asset", "id": id} for id in list(set(ids))] - - # for other entity types, return the list of entity objects unmodified - else: - entities_to_sync = [{"type": entity_type, "id": id} for id in entity_ids] + try: + specific_files = False + entities_to_sync = [] + synclog = app.engine.sgtk.synchronize_filesystem_structure() + app.log_debug(f"Synced Folders: {synclog}") - else: # if user launching without context - # we look for all project tasks assigned to the current user - user = app.context.user - user_tasks = app.context.sgtk.shotgun.find("Task", - [["task_assignees", "is", user], - ["project", "is", app.context.project], - ['sg_status_list', 'in', ['rdy', 'ip']]], - ["entity", "sg_status_list"]) - - # look through all the possible entity links to these tasks, and keep all the unique ones to send to the UI - user_assets = [] - entities_to_sync = entities_from_tasks(app, user_tasks) + if entity_type: + # if a single task were selected, or launched from a task detail page + if entity_type == "Task": + tasks = app.shotgun.find(entity_type, [['id', 'in', entity_ids]], ['entity']) + entities_to_sync = entities_from_tasks(app, tasks) + + # if assets were selected, make sure we have all the top level assets from child selections + elif entity_type == "Asset": + ids = [] + assets = app.shotgun.find(entity_type, [['id', 'in', entity_ids]], ['sg_asset_parent', 'code']) + parent_asset_ids = ids.extend([i.get('sg_asset_parent').get('id') for i in assets if i.get('sg_asset_parent')]) + asset_ids = ids.extend([i.get('id') for i in assets if not i.get('sg_asset_parent')]) + entities_to_sync = [{"type": entity_type, "id": id} for id in list(set(ids))] + app.log_info(entities_to_sync) + + elif entity_type == "PublishedFile": + specific_files = True + pfiles = app.shotgun.find(entity_type, [['id', 'in', entity_ids]], ['entity', 'path_cache', 'path']) + entities_to_sync = pfiles + app.log_info(entities_to_sync) + + elif entity_type == "Sequence": + ids = [] + asset_ids = [] + seqs = app.shotgun.find("Sequence", [['id', 'in', entity_ids]], ["assets"]) + for seq in seqs: + asset_ids.extend([i.get('id') for i in seq.get('assets')]) + assets = app.shotgun.find('Asset', [['id', 'in', asset_ids]], ['sg_asset_parent', 'code']) + parent_asset_ids = ids.extend([i.get('sg_asset_parent').get('id') for i in assets if i.get('sg_asset_parent')]) + asset_ids = ids.extend([i.get('id') for i in assets if not i.get('sg_asset_parent')]) + entities_to_sync = [{"type": "Asset", "id": id} for id in list(set(ids))] + + # for other entity types, return the list of entity objects unmodified + else: + entities_to_sync = [{"type": entity_type, "id": id} for id in entity_ids] + + + else: # if user launching without context + # we look for all project tasks assigned to the current user + user = app.context.user + user_tasks = app.context.sgtk.shotgun.find("Task", + [["task_assignees", "is", user], + ["project", "is", app.context.project], + ['sg_status_list', 'in', ['rdy', 'ip']]], + ["entity", "sg_status_list"]) + + # look through all the possible entity links to these tasks, and keep all the unique ones to send to the UI + user_assets = [] + entities_to_sync = entities_from_tasks(app, user_tasks) - try: + p4_fw = sgtk.platform.get_framework("tk-framework-perforce") p4_fw.sync.sync_with_dialog(app, entities_to_sync, specific_files) except Exception: