Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions python/connection/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
25 changes: 10 additions & 15 deletions python/sync/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
8 changes: 6 additions & 2 deletions python/sync/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
38 changes: 20 additions & 18 deletions python/widgets/sync_workers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pprint
import random
import time
from pathlib import Path

from ..sync.resolver import TemplateResolver

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down