Skip to content

Commit d1e3bd8

Browse files
committed
Fixup Publishing assets and alternate root syncing
1 parent d48b2ad commit d1e3bd8

2 files changed

Lines changed: 30 additions & 33 deletions

File tree

python/sync/resolver.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,6 @@
33
import sgtk
44
import traceback
55

6-
name_mapping = {
7-
"Animation": "CustomEntity05",
8-
"Env Asset": "CustomEntity01",
9-
}
10-
11-
root_template_mapping = {
12-
"Asset" : "asset_root",
13-
"Animation" : "anim_asset_root",
14-
"Env Asset" : "env_asset_root",
15-
"Sequence" : "sequence_root",
16-
"Shot" : "shot_root"
17-
}
18-
19-
206
class TemplateResolver:
217

228
def __init__(self, app=None, entity=None):
@@ -38,9 +24,18 @@ def root_template(self):
3824
entity_type = self.entity.get('type')
3925
if entity_type in mapping.keys():
4026
template_name = mapping.get(entity_type)
41-
return self.app.sgtk.templates.get(template_name)
27+
elif entity_type == "CustomEntity03":
28+
context_entity = self.app.sgtk.shotgun.find_one("CustomEntity03",
29+
[["id", "is", self.entity.get('id')]],
30+
["sg_asset_type"])
31+
if context_entity.get("sg_asset_type") == "Campaigns":
32+
template_name = "pub_asset_root"
33+
else:
34+
template_name = "prod_asset_root"
4235
else:
4336
raise Exception("No template specified for resolving root path for type: {}".format(entity_type))
37+
38+
return self.app.sgtk.templates.get(template_name)
4439

4540
@property
4641
def template_fields(self):

python/widgets/sync_workers.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pprint
66
import random
77
import time
8+
from pathlib import Path
89

910
from ..sync.resolver import TemplateResolver
1011

@@ -142,8 +143,8 @@ def asset_name(self):
142143
def root_path(self):
143144
rp = self.asset_item.get('root_path')
144145
if self.entity.get('type') in ["PublishedFile"]:
145-
# TODO: this needs to become dynamic
146-
rp = "B:/" + self.entity.get('path_cache')
146+
# Add the drive letter or root from the project_path
147+
rp = os.path.join(Path(self.app.sgtk.project_path).anchor.replace("\\","/"), self.entity.get('path_cache'))
147148
return rp
148149

149150
@property
@@ -185,26 +186,27 @@ def get_perforce_sync_dry_reponse(self):
185186
arguments = ["-n"]
186187
if self.force_sync:
187188
arguments.append("-f")
188-
sync_response = self.p4.run("sync", arguments, "{}#head".format(self.root_path))
189-
190-
191-
if not sync_response:
189+
try:
190+
sync_response = self.p4.run("sync", arguments, "{}#head".format(self.root_path))
191+
if not sync_response:
192+
self._status = "Syncd"
193+
self._icon = "success"
194+
self._detail = "Nothing new to sync for [{}]".format(self.root_path)
195+
else:
196+
# if the response from p4 has items... make UI elements for them
197+
self._items_to_sync = [i for i in sync_response if type(i) != str]
198+
self._status = "{} items to Sync".format(len(self._items_to_sync))
199+
self._icon = "load"
200+
self._detail = self.root_path
201+
except Exception as e:
202+
self.log_error(f"Sync Response is - {e}")
192203
self._status = "Not In Depot"
193204
self._icon = "error"
194-
self._detail = "Nothing in depot resolves [{}]".format(self.root_path)
205+
self._detail = "Nothing in depot resolves [{}]".format(self.root_path)
195206

196-
elif len(sync_response) is 1 and type(sync_response[0]) is str:
197-
self._status = "Syncd"
198-
self._icon = "success"
199-
self._detail = "Nothing new to sync for [{}]".format(self.root_path)
200-
else:
201-
# if the response from p4 has items... make UI elements for them
202-
self._items_to_sync = [i for i in sync_response if type(i) != str]
203-
self._status = "{} items to Sync".format(len(self._items_to_sync))
204-
self._icon = "load"
205-
self._detail = self.root_path
206207
if self.entity.get('type') in ['PublishedFile']:
207-
self._items_to_sync = [{"clientFile" : "B:/" + self.entity.get('path_cache')}]
208+
project_root = Path(self.app.sgtk.project_path).anchor.replace("\\","/")
209+
self._items_to_sync = [{"clientFile" : os.path.join(project_root, self.entity.get('path_cache'))}]
208210
self._status = "Exact Path"
209211
self._detail = "Exact path specified: [{}]".format(self.root_path)
210212
self._icon = "load"

0 commit comments

Comments
 (0)