New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use SG API key for creating session and remove login functionality #58
Changes from all commits
44a4ad3
3ab8b6a
4f19aa9
0dccce7
6650acf
fc64c00
4ef4407
8cea5ae
2acebd3
2742967
9bc1af9
90537a7
9b31909
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import os | ||
import re | ||
import platform | ||
|
||
import pyblish.api | ||
|
@@ -17,6 +18,12 @@ class IntegrateShotgridPublish(pyblish.api.InstancePlugin): | |
label = "Shotgrid Published Files" | ||
|
||
def process(self, instance): | ||
# Skip execution if instance is marked to be processed in the farm | ||
if instance.data.get("farm"): | ||
self.log.info( | ||
"Instance is marked to be processed on farm. Skipping") | ||
return | ||
|
||
sg_session = instance.context.data.get("shotgridSession") | ||
sg_version = instance.data.get("shotgridVersion") | ||
|
||
|
@@ -25,18 +32,33 @@ def process(self, instance): | |
|
||
for representation in instance.data.get("representations", []): | ||
|
||
if "shotgridreview" not in representation.get("tags", []): | ||
self.log.debug( | ||
"No 'shotgridreview' tag on representation '%s', skipping.", | ||
representation.get("name") | ||
) | ||
continue | ||
|
||
local_path = get_publish_repre_path( | ||
instance, representation, False | ||
) | ||
|
||
if representation.get("tags", []): | ||
continue | ||
|
||
sg_project = instance.data.get("shotgridProject") | ||
sg_entity = instance.data.get("shotgridEntity") | ||
sg_task = instance.data.get("shotgridTask") | ||
|
||
code = os.path.basename(local_path) | ||
# Extract and remove version number from code so Publishedfile versions are | ||
# grouped together. More info about this on: | ||
# https://developer.shotgridsoftware.com/tk-core/_modules/tank/util/shotgun/publish_creation.html | ||
version_number = 0 | ||
match = re.search("_v(\d+)", code) | ||
if match: | ||
version_number = int(match.group(1)) | ||
# Remove version from name | ||
code = re.sub("_v\d+", "", code) | ||
# Remove frames from name (i.e., filename.1001.exr -> filename.exr) | ||
code = re.sub("\.\d+", "", code) | ||
|
||
query_filters = [ | ||
["project", "is", sg_project], | ||
|
@@ -53,41 +75,41 @@ def process(self, instance): | |
query_filters | ||
) | ||
|
||
sg_local_store = sg_session.find_one( | ||
sg_local_storage = sg_session.find_one( | ||
"LocalStorage", | ||
filters=[], | ||
fields=["mac_path","windows_path", "linux_path"] | ||
fields=["mac_path", "windows_path", "linux_path"] | ||
) | ||
|
||
if not sg_local_store: | ||
if not sg_local_storage: | ||
KnownPublishError( | ||
"Unable to find a Local Store in Shotgrid." | ||
"Unable to find a Local Storage in Shotgrid." | ||
"Enable them in Site Preferences > Local Management:" | ||
"https://help.autodesk.com/view/SGSUB/ENU/?guid=SG_Administrator_ar_data_management_ar_linking_local_files_html" | ||
) | ||
|
||
self.log.debug("Using the Local Store: {sg_local_store}") | ||
self.log.debug("Using the Local Storage: {sg_local_storage}") | ||
|
||
try: | ||
if platform.system() == "Windows": | ||
_, file_partial_path = local_path.split( | ||
sg_local_store["windows_path"] | ||
sg_local_storage["windows_path"] | ||
) | ||
file_partial_path = file_partial_path.replace("\\", "/") | ||
elif platform.system() == "Linux": | ||
_, file_partial_path = local_path.split( | ||
sg_local_store["linux_path"] | ||
sg_local_storage["linux_path"] | ||
) | ||
elif platform.system() == "Darwin": | ||
_, file_partial_path = local_path.split( | ||
sg_local_store["mac_path"] | ||
sg_local_storage["mac_path"] | ||
) | ||
|
||
file_partial_path = file_partial_path.lstrip("/") | ||
except ValueError: | ||
raise KnownPublishError( | ||
f"Filepath {local_path} doesn't match the " | ||
f"Shotgrid Local Store {sg_local_store}" | ||
f"Shotgrid Local Storage {sg_local_storage}" | ||
"Enable them in Site Preferences > Local Management:" | ||
"https://help.autodesk.com/view/SGSUB/ENU/?guid=SG_Administrator_ar_data_management_ar_linking_local_files_html" | ||
) | ||
|
@@ -98,9 +120,14 @@ def process(self, instance): | |
"entity": sg_entity, | ||
"version": sg_version, | ||
"path": { | ||
"local_storage": sg_local_store, | ||
"local_storage": sg_local_storage, | ||
"relative_path": file_partial_path | ||
}, | ||
# Add file type and version number fields | ||
"published_file_type": self._find_published_file_type( | ||
instance, local_path, representation | ||
), | ||
"version_number": version_number, | ||
} | ||
|
||
if sg_task: | ||
|
@@ -141,3 +168,43 @@ def process(self, instance): | |
) | ||
instance.data["shotgridPublishedFile"] = sg_published_file | ||
|
||
def _find_published_file_type(self, instance, filepath, representation): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah this is great too, how would you select what SH publish type (representation) you're publishing too? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. atm I'm not making use of the Ayon family or representation name, I'm purely basing it off the extension of the file type and you don't have to do anything extra, just that this function detects all the file types you want to track |
||
"""Given a filepath infer what type of published file type it is.""" | ||
|
||
_, ext = os.path.splitext(filepath) | ||
published_file_type = "Unknown" | ||
|
||
if ext in [".exr", ".jpg", ".jpeg", ".png", ".dpx", ".tif", ".tiff"]: | ||
is_sequence = len(representation["files"]) > 1 | ||
if is_sequence: | ||
published_file_type = "Rendered Image" | ||
else: | ||
published_file_type = "Image" | ||
elif ext in [".mov", ".mp4"]: | ||
published_file_type = "Movie" | ||
elif ext == ".abc": | ||
published_file_type = "Alembic Cache" | ||
elif ext in [".bgeo", ".sc", ".gz"]: | ||
published_file_type = "Bgeo Geo" | ||
elif ext in [".ma", ".mb"]: | ||
published_file_type = "Maya Scene" | ||
elif ext == ".nk": | ||
published_file_type = "Nuke Script" | ||
elif ext == ".hip": | ||
published_file_type = "Houdini Scene" | ||
elif ext in [".hda"]: | ||
published_file_type = "HDA" | ||
elif ext in [".fbx"]: | ||
published_file_type = "FBX Geo" | ||
|
||
filters = [["code", "is", published_file_type]] | ||
sg_session = instance.context.data.get("shotgridSession") | ||
sg_published_file_type = sg_session.find_one( | ||
"PublishedFileType", filters=filters | ||
) | ||
if not sg_published_file_type: | ||
# Create a published file type on the fly | ||
sg_published_file_type = sg_session.create( | ||
"PublishedFileType", {"code": published_file_type} | ||
) | ||
return sg_published_file_type |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do you normally define this environment variable, and what should happen if it's not set empty?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on my case I'm actually just using
$USER
as all our artists machines have that defined so we don't need any extra user input to define their login for SG but that's why I left it open to discuss. We could potentially expose an option on the settings where admins can choose any existing env var to use as SG login and/or optionally expose the login menu so each user can set it themselves on the registry