Address feedback on PR and move function to pipeline.publish.lib

This commit is contained in:
Fabia Serra Arrizabalaga 2023-02-08 20:23:26 +01:00
parent c13416b685
commit 27150e4abb
7 changed files with 59 additions and 57 deletions

View file

@ -3,6 +3,7 @@ import json
import copy
import pyblish.api
from openpype.pipeline.publish import get_publish_repre_path
from openpype.lib.openpype_version import get_openpype_version
from openpype.lib.transcoding import (
get_ffprobe_streams,
@ -10,7 +11,6 @@ from openpype.lib.transcoding import (
)
from openpype.lib.profiles_filtering import filter_profiles
from openpype.lib.transcoding import VIDEO_EXTENSIONS
from openpype.plugins.publish.integrate import get_representation_path
class IntegrateFtrackInstance(pyblish.api.InstancePlugin):
@ -154,7 +154,7 @@ class IntegrateFtrackInstance(pyblish.api.InstancePlugin):
if not review_representations or has_movie_review:
for repre in thumbnail_representations:
repre_path = get_representation_path(instance, repre, False)
repre_path = get_publish_repre_path(instance, repre, False)
if not repre_path:
self.log.warning(
"Published path is not set and source was removed."
@ -211,7 +211,7 @@ class IntegrateFtrackInstance(pyblish.api.InstancePlugin):
"from {}".format(repre))
continue
repre_path = get_representation_path(instance, repre, False)
repre_path = get_publish_repre_path(instance, repre, False)
if not repre_path:
self.log.warning(
"Published path is not set and source was removed."
@ -325,7 +325,7 @@ class IntegrateFtrackInstance(pyblish.api.InstancePlugin):
# Add others representations as component
for repre in other_representations:
published_path = get_representation_path(instance, repre, True)
published_path = get_publish_repre_path(instance, repre, True)
if not published_path:
continue
# Create copy of base comp item and append it

View file

@ -1,7 +1,7 @@
import os
import pyblish.api
from openpype.plugins.publish.integrate import get_representation_path
from openpype.pipeline.publish import get_publish_repre_path
class IntegrateShotgridPublish(pyblish.api.InstancePlugin):
@ -24,7 +24,7 @@ class IntegrateShotgridPublish(pyblish.api.InstancePlugin):
for representation in instance.data.get("representations", []):
local_path = get_representation_path(
local_path = get_publish_repre_path(
instance, representation, False
)
code = os.path.basename(local_path)

View file

@ -1,6 +1,6 @@
import pyblish.api
from openpype.plugins.publish.integrate import get_representation_path
from openpype.pipeline.publish import get_publish_repre_path
class IntegrateShotgridVersion(pyblish.api.InstancePlugin):
@ -42,7 +42,7 @@ class IntegrateShotgridVersion(pyblish.api.InstancePlugin):
data_to_update["sg_status_list"] = status
for representation in instance.data.get("representations", []):
local_path = get_representation_path(
local_path = get_publish_repre_path(
instance, representation, False
)

View file

@ -8,8 +8,8 @@ from abc import ABCMeta, abstractmethod
import time
from openpype.client import OpenPypeMongoConnection
from openpype.pipeline.publish import get_publish_repre_path
from openpype.lib.plugin_tools import prepare_template_data
from openpype.plugins.publish.integrate import get_representation_path
class IntegrateSlackAPI(pyblish.api.InstancePlugin):
@ -168,7 +168,7 @@ class IntegrateSlackAPI(pyblish.api.InstancePlugin):
thumbnail_path = None
for repre in instance.data.get("representations", []):
if repre.get('thumbnail') or "thumbnail" in repre.get('tags', []):
repre_thumbnail_path = get_representation_path(
repre_thumbnail_path = get_publish_repre_path(
instance, repre, False
)
if os.path.exists(repre_thumbnail_path):
@ -184,7 +184,7 @@ class IntegrateSlackAPI(pyblish.api.InstancePlugin):
if (repre.get("review")
or "review" in tags
or "burnin" in tags):
repre_review_path = get_representation_path(
repre_review_path = get_publish_repre_path(
instance, repre, False
)
if os.path.exists(repre_review_path):

View file

@ -36,6 +36,7 @@ from .lib import (
filter_instances_for_context_plugin,
context_plugin_should_run,
get_instance_staging_dir,
get_publish_repre_path,
)
from .abstract_expected_files import ExpectedFiles
@ -79,6 +80,7 @@ __all__ = (
"filter_instances_for_context_plugin",
"context_plugin_should_run",
"get_instance_staging_dir",
"get_publish_repre_path",
"ExpectedFiles",

View file

@ -632,3 +632,49 @@ def get_instance_staging_dir(instance):
instance.data["stagingDir"] = staging_dir
return staging_dir
def get_publish_repre_path(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 = get_instance_staging_dir(instance)
src_path = os.path.normpath(os.path.join(staging_dir, filename))
if os.path.exists(src_path):
return src_path
return None

View file

@ -53,52 +53,6 @@ def get_frame_padded(frame, padding):
return "{frame:0{padding}d}".format(padding=padding, frame=frame)
def get_representation_path(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
class IntegrateAsset(pyblish.api.InstancePlugin):
"""Register publish in the database and transfer files to destinations.