use the new function

This commit is contained in:
Jakub Trllo 2025-09-24 12:14:21 +02:00
parent 80ba7ea5ed
commit 60ff1ddb0c
3 changed files with 52 additions and 61 deletions

View file

@ -11,7 +11,7 @@ import clique
from ayon_core.lib import Logger from ayon_core.lib import Logger
from ayon_core.pipeline import ( from ayon_core.pipeline import (
get_current_project_name, get_current_project_name,
get_representation_path, get_representation_path_v2,
) )
from ayon_core.pipeline.create import get_product_name from ayon_core.pipeline.create import get_product_name
from ayon_core.pipeline.farm.patterning import match_aov_pattern from ayon_core.pipeline.farm.patterning import match_aov_pattern
@ -1044,7 +1044,9 @@ def get_resources(project_name, version_entity, extension=None):
filtered.append(repre_entity) filtered.append(repre_entity)
representation = filtered[0] representation = filtered[0]
directory = get_representation_path(representation) directory = get_representation_path_v2(
project_name, representation
)
print("Source: ", directory) print("Source: ", directory)
resources = sorted( resources = sorted(
[ [

View file

@ -1,3 +1,5 @@
from __future__ import annotations
import os import os
import uuid import uuid
import platform import platform
@ -5,6 +7,7 @@ import logging
import inspect import inspect
import collections import collections
import numbers import numbers
import copy
from typing import Optional, Union, Any from typing import Optional, Union, Any
import ayon_api import ayon_api
@ -694,15 +697,15 @@ def get_representation_path_from_context(context):
representation = context["representation"] representation = context["representation"]
project_entity = context.get("project") project_entity = context.get("project")
root = None if project_entity:
if ( project_name = project_entity["name"]
project_entity else:
and project_entity["name"] != get_current_project_name() project_name = get_current_project_name()
): return get_representation_path_v2(
anatomy = Anatomy(project_entity["name"]) project_name,
root = anatomy.roots representation,
project_entity=project_entity,
return get_representation_path(representation, root) )
def get_representation_path_with_anatomy(repre_entity, anatomy): def get_representation_path_with_anatomy(repre_entity, anatomy):
@ -721,36 +724,18 @@ def get_representation_path_with_anatomy(repre_entity, anatomy):
anatomy (Anatomy): Project anatomy object. anatomy (Anatomy): Project anatomy object.
Returns: Returns:
Union[None, TemplateResult]: None if path can't be received TemplateResult: Resolved representation path.
Raises: Raises:
InvalidRepresentationContext: When representation data are probably InvalidRepresentationContext: When representation data are probably
invalid or not available. invalid or not available.
""" """
return get_representation_path_v2(
try: anatomy.project_name,
template = repre_entity["attrib"]["template"] repre_entity,
anatomy=anatomy,
except KeyError: )
raise InvalidRepresentationContext((
"Representation document does not"
" contain template in data ('data.template')"
))
try:
context = repre_entity["context"]
_fix_representation_context_compatibility(context)
context["root"] = anatomy.roots
path = StringTemplate.format_strict_template(template, context)
except TemplateUnsolved as exc:
raise InvalidRepresentationContext((
"Couldn't resolve representation template with available data."
" Reason: {}".format(str(exc))
))
return path.normalized()
def get_representation_path(representation, root=None): def get_representation_path(representation, root=None):
@ -771,11 +756,12 @@ def get_representation_path(representation, root=None):
""" """
if root is None: if root is None:
from ayon_core.pipeline import get_current_project_name, Anatomy from ayon_core.pipeline import get_current_project_name
anatomy = Anatomy(get_current_project_name()) project_name = get_current_project_name()
return get_representation_path_with_anatomy( return get_representation_path_v2(
representation, anatomy project_name,
representation,
) )
def path_from_representation(): def path_from_representation():
@ -848,12 +834,13 @@ def get_representation_path(representation, root=None):
def get_representation_path_by_names( def get_representation_path_by_names(
project_name: str, project_name: str,
folder_path: str, folder_path: str,
product_name: str, product_name: str,
version_name: str, version_name: str,
representation_name: str, representation_name: str,
anatomy: Optional[Anatomy] = None) -> Optional[str]: anatomy: Optional[Anatomy] = None
) -> Optional[TemplateResult]:
"""Get (latest) filepath for representation for folder and product. """Get (latest) filepath for representation for folder and product.
See `get_representation_by_names` for more details. See `get_representation_by_names` for more details.
@ -870,22 +857,21 @@ def get_representation_path_by_names(
representation_name representation_name
) )
if not representation: if not representation:
return return None
if not anatomy: return get_representation_path_v2(
anatomy = Anatomy(project_name) project_name,
representation,
if representation: anatomy=anatomy,
path = get_representation_path_with_anatomy(representation, anatomy) )
return str(path).replace("\\", "/")
def get_representation_by_names( def get_representation_by_names(
project_name: str, project_name: str,
folder_path: str, folder_path: str,
product_name: str, product_name: str,
version_name: Union[int, str], version_name: Union[int, str],
representation_name: str, representation_name: str,
) -> Optional[dict]: ) -> Optional[dict]:
"""Get representation entity for asset and subset. """Get representation entity for asset and subset.
@ -902,7 +888,7 @@ def get_representation_by_names(
folder_entity = ayon_api.get_folder_by_path( folder_entity = ayon_api.get_folder_by_path(
project_name, folder_path, fields=["id"]) project_name, folder_path, fields=["id"])
if not folder_entity: if not folder_entity:
return return None
if isinstance(product_name, dict) and "name" in product_name: if isinstance(product_name, dict) and "name" in product_name:
# Allow explicitly passing subset document # Allow explicitly passing subset document
@ -914,7 +900,7 @@ def get_representation_by_names(
folder_id=folder_entity["id"], folder_id=folder_entity["id"],
fields=["id"]) fields=["id"])
if not product_entity: if not product_entity:
return return None
if version_name == "hero": if version_name == "hero":
version_entity = ayon_api.get_hero_version_by_product_id( version_entity = ayon_api.get_hero_version_by_product_id(
@ -926,7 +912,7 @@ def get_representation_by_names(
version_entity = ayon_api.get_version_by_name( version_entity = ayon_api.get_version_by_name(
project_name, version_name, product_id=product_entity["id"]) project_name, version_name, product_id=product_entity["id"])
if not version_entity: if not version_entity:
return return None
return ayon_api.get_representation_by_name( return ayon_api.get_representation_by_name(
project_name, representation_name, version_id=version_entity["id"]) project_name, representation_name, version_id=version_entity["id"])

View file

@ -1,6 +1,7 @@
from operator import attrgetter from operator import attrgetter
import dataclasses import dataclasses
import os import os
import platform
from typing import Any, Dict, List from typing import Any, Dict, List
import pyblish.api import pyblish.api
@ -179,6 +180,8 @@ def get_instance_uri_path(
# Ensure `None` for now is also a string # Ensure `None` for now is also a string
path = str(path) path = str(path)
if platform.system().lower() == "windows":
path = path.replace("\\", "/")
return path return path