diff --git a/info.yml b/info.yml index 25ad6e8..3f4e1ea 100644 --- a/info.yml +++ b/info.yml @@ -6,7 +6,7 @@ configuration: description: "The name of the project entity field that contains the perforce server to connect to. The value in the field should be of the form: 'protocol:server:port'." allows_empty: True - default_value: sg_p4_server + default_value: sg_perforce_server server_aliases: type: list diff --git a/python/connection/connection.py b/python/connection/connection.py index 16d3399..a9f6fe9 100644 --- a/python/connection/connection.py +++ b/python/connection/connection.py @@ -769,15 +769,19 @@ def _login_required(self, min_timeout=300): return True def _get_p4_server(self): + user = sgtk.util.get_current_user(self._fw.sgtk) + sg_user = self._fw.shotgun.find_one('HumanUser', [['id', 'is', user['id']]], ["sg_region"]) server_field = self._fw.get_setting("server_field") sg_project = self._fw.shotgun.find_one('Project', [['id', 'is', self._fw.context.project['id']]], [server_field]) server = sg_project.get(server_field) + region = sg_user.get("sg_region") + sg_server = self._fw.shotgun.find_one('CustomNonProjectEntity02', [['id', 'is', server['id']]], [region]) - if not server: + if not sg_server: self._fw.log_error("No server was configured for this project! Enter the p4 server in the project field '{}'".format(server_field)) return None - return str(sg_project.get(server_field)) + return str(sg_server.get(region)) def connect(allow_ui=True, user=None, password=None, workspace=None, progress=None): diff --git a/python/sync/resolver.py b/python/sync/resolver.py index c3164dc..e5b83d7 100644 --- a/python/sync/resolver.py +++ b/python/sync/resolver.py @@ -3,20 +3,6 @@ import sgtk import traceback -name_mapping = { - "Animation": "CustomEntity05", - "Env Asset": "CustomEntity01", -} - -root_template_mapping = { - "Asset" : "asset_root", - "Animation" : "anim_asset_root", - "Env Asset" : "env_asset_root", - "Sequence" : "sequence_root", - "Shot" : "shot_root" -} - - class TemplateResolver: def __init__(self, app=None, entity=None): @@ -38,9 +24,18 @@ def root_template(self): entity_type = self.entity.get('type') if entity_type in mapping.keys(): template_name = mapping.get(entity_type) - return self.app.sgtk.templates.get(template_name) + elif entity_type == "CustomEntity03": + context_entity = self.app.sgtk.shotgun.find_one("CustomEntity03", + [["id", "is", self.entity.get('id')]], + ["sg_asset_type"]) + if context_entity.get("sg_asset_type") == "Campaigns": + template_name = "pub_asset_root" + else: + template_name = "prod_asset_root" else: raise Exception("No template specified for resolving root path for type: {}".format(entity_type)) + + return self.app.sgtk.templates.get(template_name) @property def template_fields(self): diff --git a/python/sync/sync.py b/python/sync/sync.py index 42235e2..9ab9265 100644 --- a/python/sync/sync.py +++ b/python/sync/sync.py @@ -92,15 +92,19 @@ def _sync_with_dlg(self): def _get_p4_server(self): + user = sgtk.util.get_current_user(self._fw.sgtk) + sg_user = self._fw.shotgun.find_one('HumanUser', [['id', 'is', user['id']]], ["sg_region"]) server_field = self._fw.get_setting("server_field") sg_project = self._fw.shotgun.find_one('Project', [['id', 'is', self._fw.context.project['id']]], [server_field]) server = sg_project.get(server_field) + region = sg_user.get("sg_region") + sg_server = self._fw.shotgun.find_one('CustomNonProjectEntity02', [['id', 'is', server['id']]], [region]) - if not server: + if not sg_server: self._fw.log_error("No server was configured for this project! Enter the p4 server in the project field '{}'".format(server_field)) return None - return str(sg_project.get(server_field)) + return str(sg_server.get(region)) def sync_with_dialog(app, entities_to_sync, specific_files=False): diff --git a/python/widgets/sync_workers.py b/python/widgets/sync_workers.py index d3bd226..1ef4922 100644 --- a/python/widgets/sync_workers.py +++ b/python/widgets/sync_workers.py @@ -5,6 +5,7 @@ import pprint import random import time +from pathlib import Path from ..sync.resolver import TemplateResolver @@ -142,8 +143,8 @@ def asset_name(self): def root_path(self): rp = self.asset_item.get('root_path') if self.entity.get('type') in ["PublishedFile"]: - # TODO: this needs to become dynamic - rp = "B:/" + self.entity.get('path_cache') + # Add the drive letter or root from the project_path + rp = os.path.join(Path(self.app.sgtk.project_path).anchor.replace("\\","/"), self.entity.get('path_cache')) return rp @property @@ -185,26 +186,27 @@ def get_perforce_sync_dry_reponse(self): arguments = ["-n"] if self.force_sync: arguments.append("-f") - sync_response = self.p4.run("sync", arguments, "{}#head".format(self.root_path)) - - - if not sync_response: + try: + sync_response = self.p4.run("sync", arguments, "{}#head".format(self.root_path)) + if not sync_response: + self._status = "Syncd" + self._icon = "success" + self._detail = "Nothing new to sync for [{}]".format(self.root_path) + else: + # if the response from p4 has items... make UI elements for them + self._items_to_sync = [i for i in sync_response if type(i) != str] + self._status = "{} items to Sync".format(len(self._items_to_sync)) + self._icon = "load" + self._detail = self.root_path + except Exception as e: + self.log_error(f"Sync Response is - {e}") self._status = "Not In Depot" self._icon = "error" - self._detail = "Nothing in depot resolves [{}]".format(self.root_path) + self._detail = "Nothing in depot resolves [{}]".format(self.root_path) - elif len(sync_response) is 1 and type(sync_response[0]) is str: - self._status = "Syncd" - self._icon = "success" - self._detail = "Nothing new to sync for [{}]".format(self.root_path) - else: - # if the response from p4 has items... make UI elements for them - self._items_to_sync = [i for i in sync_response if type(i) != str] - self._status = "{} items to Sync".format(len(self._items_to_sync)) - self._icon = "load" - self._detail = self.root_path if self.entity.get('type') in ['PublishedFile']: - self._items_to_sync = [{"clientFile" : "B:/" + self.entity.get('path_cache')}] + project_root = Path(self.app.sgtk.project_path).anchor.replace("\\","/") + self._items_to_sync = [{"clientFile" : os.path.join(project_root, self.entity.get('path_cache'))}] self._status = "Exact Path" self._detail = "Exact path specified: [{}]".format(self.root_path) self._icon = "load"