marked 'path_from_representation' as deprecated and replaced it's usage with 'get_representation_path_with_anatomy'

This commit is contained in:
Jakub Trllo 2022-08-29 14:41:28 +02:00
parent 315cf40d8b
commit f2a191861b
5 changed files with 43 additions and 42 deletions

View file

@ -7,11 +7,6 @@ import collections
import functools import functools
import warnings import warnings
from .path_templates import (
StringTemplate,
TemplateUnsolved,
)
class DeliveryDeprecatedWarning(DeprecationWarning): class DeliveryDeprecatedWarning(DeprecationWarning):
pass pass
@ -88,24 +83,22 @@ def sizeof_fmt(num, suffix=None):
return format_file_size(num, suffix) return format_file_size(num, suffix)
@deprecated("openpype.pipeline.load.get_representation_path_with_anatomy")
def path_from_representation(representation, anatomy): def path_from_representation(representation, anatomy):
try: """Get representation path using representation document and anatomy.
template = representation["data"]["template"]
except KeyError: Args:
return None representation (Dict[str, Any]): Representation document.
anatomy (Anatomy): Project anatomy.
try: Deprecated:
context = representation["context"] Function was moved to different location and will be removed
context["root"] = anatomy.roots after 3.16.* release.
path = StringTemplate.format_strict_template(template, context) """
return os.path.normpath(path)
except TemplateUnsolved: from openpype.pipeline.load import get_representation_path_with_anatomy
# Template references unavailable data
return None
return path return get_representation_path_with_anatomy(representation, anatomy)
def copy_file(src_path, dst_path): def copy_file(src_path, dst_path):

View file

@ -10,15 +10,15 @@ from openpype.client import (
get_versions, get_versions,
get_representations get_representations
) )
from openpype.pipeline import Anatomy
from openpype_modules.ftrack.lib import BaseAction, statics_icon from openpype_modules.ftrack.lib import BaseAction, statics_icon
from openpype_modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY from openpype_modules.ftrack.lib.avalon_sync import CUST_ATTR_ID_KEY
from openpype_modules.ftrack.lib.custom_attributes import ( from openpype_modules.ftrack.lib.custom_attributes import (
query_custom_attributes query_custom_attributes
) )
from openpype.lib.dateutils import get_datetime_data from openpype.lib.dateutils import get_datetime_data
from openpype.pipeline import Anatomy
from openpype.pipeline.load import get_representation_path_with_anatomy
from openpype.lib.delivery import ( from openpype.lib.delivery import (
path_from_representation,
get_format_dict, get_format_dict,
check_destination_path, check_destination_path,
process_single_file, process_single_file,
@ -580,7 +580,7 @@ class Delivery(BaseAction):
if frame: if frame:
repre["context"]["frame"] = len(str(frame)) * "#" repre["context"]["frame"] = len(str(frame)) * "#"
repre_path = path_from_representation(repre, anatomy) repre_path = get_representation_path_with_anatomy(repre, anatomy)
# TODO add backup solution where root of path from component # TODO add backup solution where root of path from component
# is replaced with root # is replaced with root
args = ( args = (

View file

@ -71,6 +71,7 @@ __all__ = (
"get_representation_path_from_context", "get_representation_path_from_context",
"get_representation_path", "get_representation_path",
"get_representation_path_with_anatomy",
"is_compatible_loader", "is_compatible_loader",

View file

@ -7,11 +7,15 @@ from pymongo import UpdateOne
import qargparse import qargparse
from Qt import QtWidgets, QtCore from Qt import QtWidgets, QtCore
from openpype.client import get_versions, get_representations
from openpype import style from openpype import style
from openpype.pipeline import load, AvalonMongoDB, Anatomy from openpype.client import get_versions, get_representations
from openpype.lib import StringTemplate, format_file_size
from openpype.modules import ModulesManager from openpype.modules import ModulesManager
from openpype.lib import StringTemplate, format_file_size
from openpype.pipeline import load, AvalonMongoDB, Anatomy
from openpype.pipeline.load import (
get_representation_path_with_anatomy,
InvalidRepresentationContext,
)
class DeleteOldVersions(load.SubsetLoaderPlugin): class DeleteOldVersions(load.SubsetLoaderPlugin):
@ -73,27 +77,28 @@ class DeleteOldVersions(load.SubsetLoaderPlugin):
def path_from_representation(self, representation, anatomy): def path_from_representation(self, representation, anatomy):
try: try:
template = representation["data"]["template"] context = representation["context"]
except KeyError: except KeyError:
return (None, None) return (None, None)
try:
path = get_representation_path_with_anatomy(
representation, anatomy
)
except InvalidRepresentationContext:
return (None, None)
sequence_path = None sequence_path = None
try: if "frame" in context:
context = representation["context"] context["frame"] = self.sequence_splitter
context["root"] = anatomy.roots sequence_path = get_representation_path_with_anatomy(
path = str(StringTemplate.format_template(template, context)) representation, anatomy
if "frame" in context: )
context["frame"] = self.sequence_splitter
sequence_path = os.path.normpath(str(
StringTemplate.format_template(template, context)
))
except KeyError: if sequence_path:
# Template references unavailable data sequence_path = sequence_path.normalized()
return (None, None)
return (os.path.normpath(path), sequence_path) return (path.normalized(), sequence_path)
def delete_only_repre_files(self, dir_paths, file_paths, delete=True): def delete_only_repre_files(self, dir_paths, file_paths, delete=True):
size = 0 size = 0

View file

@ -10,10 +10,10 @@ from openpype import resources, style
from openpype.lib import ( from openpype.lib import (
format_file_size, format_file_size,
collect_frames, collect_frames,
get_datetime_data,
) )
from openpype.lib.dateutils import get_datetime_data from openpype.pipeline.load import get_representation_path_with_anatomy
from openpype.lib.delivery import ( from openpype.lib.delivery import (
path_from_representation,
get_format_dict, get_format_dict,
check_destination_path, check_destination_path,
process_single_file, process_single_file,
@ -169,7 +169,9 @@ class DeliveryOptionsDialog(QtWidgets.QDialog):
if repre["name"] not in selected_repres: if repre["name"] not in selected_repres:
continue continue
repre_path = path_from_representation(repre, self.anatomy) repre_path = get_representation_path_with_anatomy(
repre, self.anatomy
)
anatomy_data = copy.deepcopy(repre["context"]) anatomy_data = copy.deepcopy(repre["context"])
new_report_items = check_destination_path(str(repre["_id"]), new_report_items = check_destination_path(str(repre["_id"]),