Skip to content
Open
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
118 changes: 61 additions & 57 deletions python/tk_multi_perforce/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import os
import pprint
import sys
import traceback

import sgtk

Expand Down Expand Up @@ -52,68 +53,71 @@ 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:
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 = []
Expand Down