Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Ftrack: Handle missing published path in integrator #3570

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class IntegrateFtrackApi(pyblish.api.InstancePlugin):
families = ["ftrack"]

def process(self, instance):
session = instance.context.data["ftrackSession"]
context = instance.context
component_list = instance.data.get("ftrackComponentsList")
if not component_list:
self.log.info(
Expand All @@ -36,8 +34,8 @@ def process(self, instance):
)
return

session = instance.context.data["ftrackSession"]
context = instance.context
session = context.data["ftrackSession"]

parent_entity = None
default_asset_name = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def process(self, instance):
version_number = int(instance_version)

family = instance.data["family"]
family_low = instance.data["family"].lower()
family_low = family.lower()

asset_type = instance.data.get("ftrackFamily")
if not asset_type and family_low in self.family_mapping:
Expand Down Expand Up @@ -140,24 +140,16 @@ def process(self, instance):
first_thumbnail_component = None
first_thumbnail_component_repre = None
for repre in thumbnail_representations:
published_path = repre.get("published_path")
if not published_path:
comp_files = repre["files"]
if isinstance(comp_files, (tuple, list, set)):
filename = comp_files[0]
else:
filename = comp_files

published_path = os.path.join(
repre["stagingDir"], filename
repre_path = self._get_repre_path(instance, repre, False)
if not repre_path:
self.log.warning(
"Published path is not set and source was removed."
)
if not os.path.exists(published_path):
continue
repre["published_path"] = published_path
continue

# Create copy of base comp item and append it
thumbnail_item = copy.deepcopy(base_component_item)
thumbnail_item["component_path"] = repre["published_path"]
thumbnail_item["component_path"] = repre_path
thumbnail_item["component_data"] = {
"name": "thumbnail"
}
Expand Down Expand Up @@ -216,6 +208,13 @@ def process(self, instance):
extended_asset_name = ""
multiple_reviewable = len(review_representations) > 1
for repre in review_representations:
repre_path = self._get_repre_path(instance, repre, False)
if not repre_path:
self.log.warning(
"Published path is not set and source was removed."
)
continue

# Create copy of base comp item and append it
review_item = copy.deepcopy(base_component_item)

Expand Down Expand Up @@ -270,7 +269,7 @@ def process(self, instance):
fps = instance_fps

# Change location
review_item["component_path"] = repre["published_path"]
review_item["component_path"] = repre_path
# Change component data
review_item["component_data"] = {
# Default component name is "main".
Expand Down Expand Up @@ -327,7 +326,7 @@ def process(self, instance):

# Add others representations as component
for repre in other_representations:
published_path = repre.get("published_path")
published_path = self._get_repre_path(instance, repre, True)
if not published_path:
continue
# Create copy of base comp item and append it
Expand Down Expand Up @@ -360,6 +359,51 @@ def json_obj_parser(obj):
))
instance.data["ftrackComponentsList"] = component_list

def _get_repre_path(self, instance, repre, only_published):
"""Get representation path that can be used for integration.
When 'only_published' is set to true the validation of path is not
relevant. In that case we just need what is set in 'published_path'
as "reference". The reference is not used to get or upload the file but
for reference where the file was published.
Args:
instance (pyblish.Instance): Processed instance object. Used
for source of staging dir if representation does not have
filled it.
repre (dict): Representation on instance which could be and
could not be integrated with main integrator.
only_published (bool): Care only about published paths and
ignore if filepath is not existing anymore.
Returns:
str: Path to representation file.
None: Path is not filled or does not exists.
"""

published_path = repre.get("published_path")
if published_path:
published_path = os.path.normpath(published_path)
if os.path.exists(published_path):
return published_path

if only_published:
return published_path

comp_files = repre["files"]
if isinstance(comp_files, (tuple, list, set)):
filename = comp_files[0]
else:
filename = comp_files

staging_dir = repre.get("stagingDir")
if not staging_dir:
staging_dir = instance.data["stagingDir"]
src_path = os.path.normpath(os.path.join(staging_dir, filename))
if os.path.exists(src_path):
return src_path
return None

def _get_asset_version_status_name(self, instance):
if not self.asset_versions_status_profiles:
return None
Expand Down