From e5c78edd6f14dd8b63770df3d745fa9b577db20e Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Wed, 6 Mar 2024 11:00:20 +0100 Subject: [PATCH] hosts are using version entities --- client/ayon_core/hosts/flame/api/plugin.py | 8 ++--- client/ayon_core/hosts/hiero/api/plugin.py | 7 ++-- .../plugins/publish/extract_usd_layered.py | 13 +++----- client/ayon_core/hosts/maya/api/lib.py | 24 ++++++-------- client/ayon_core/hosts/maya/api/setdress.py | 15 ++++----- .../hosts/maya/tools/mayalookassigner/app.py | 10 +++--- .../tools/mayalookassigner/arnold_standin.py | 18 ++++++----- .../tools/mayalookassigner/vray_proxies.py | 23 ++++++------- client/ayon_core/hosts/nuke/api/lib.py | 32 +++++++++---------- .../publish/collect_published_version.py | 8 ++--- .../hosts/traypublisher/api/plugin.py | 7 ++-- .../publish/submit_publish_cache_job.py | 22 ++++++------- .../plugins/publish/submit_publish_job.py | 22 ++++++------- 13 files changed, 101 insertions(+), 108 deletions(-) diff --git a/client/ayon_core/hosts/flame/api/plugin.py b/client/ayon_core/hosts/flame/api/plugin.py index cf28a3cef3..b00ff636ed 100644 --- a/client/ayon_core/hosts/flame/api/plugin.py +++ b/client/ayon_core/hosts/flame/api/plugin.py @@ -748,11 +748,9 @@ class ClipLoader(LoaderPlugin): Returns: str: colorspace name or None """ - version = context['version'] - version_data = version.get("data", {}) - colorspace = version_data.get( - "colorspace", None - ) + version_entity = context["version"] + version_attributes = version_entity["attrib"] + colorspace = version_attributes.get("colorSpace") if ( not colorspace diff --git a/client/ayon_core/hosts/hiero/api/plugin.py b/client/ayon_core/hosts/hiero/api/plugin.py index 667dc2af6c..cf3b4dadaf 100644 --- a/client/ayon_core/hosts/hiero/api/plugin.py +++ b/client/ayon_core/hosts/hiero/api/plugin.py @@ -454,7 +454,7 @@ class ClipLoader: representation = repr["name"] self.data["clip_name"] = self.clip_name_template.format(**repr_cntx) self.data["track_name"] = "_".join([product_name, representation]) - self.data["versionData"] = self.context["version"]["data"] + self.data["versionAttributes"] = self.context["version"]["attrib"] # gets file path file = get_representation_path_from_context(self.context) if not file: @@ -518,8 +518,9 @@ class ClipLoader: self.media_duration = int(self.media.duration()) # get handles - self.handle_start = self.data["versionData"].get("handleStart") - self.handle_end = self.data["versionData"].get("handleEnd") + version_attributes = self.data["versionAttributes"] + self.handle_start = version_attributes.get("handleStart") + self.handle_end = version_attributes.get("handleEnd") if self.handle_start is None: self.handle_start = self.data["folderAttributes"]["handleStart"] if self.handle_end is None: diff --git a/client/ayon_core/hosts/houdini/plugins/publish/extract_usd_layered.py b/client/ayon_core/hosts/houdini/plugins/publish/extract_usd_layered.py index fc9feadd40..33ab7ef43c 100644 --- a/client/ayon_core/hosts/houdini/plugins/publish/extract_usd_layered.py +++ b/client/ayon_core/hosts/houdini/plugins/publish/extract_usd_layered.py @@ -7,10 +7,7 @@ from collections import deque import ayon_api import pyblish.api -from ayon_core.client import ( - get_last_version_by_subset_id, - get_representation_by_name, -) +from ayon_core.client import get_representation_by_name from ayon_core.pipeline import ( get_representation_path, publish, @@ -297,15 +294,15 @@ class ExtractUSDLayered(publish.Extractor): self.log.debug("No existing product..") return False - version_doc = get_last_version_by_subset_id( - project_name, product_entity["id"], fields=["_id"] + version_entity = ayon_api.get_last_version_by_product_id( + project_name, product_entity["id"], fields={"id"} ) - if not version_doc: + if not version_entity: self.log.debug("No existing version..") return False representation = get_representation_by_name( - project_name, ext.lstrip("."), version_doc["_id"] + project_name, ext.lstrip("."), version_entity["id"] ) if not representation: self.log.debug("No existing representation..") diff --git a/client/ayon_core/hosts/maya/api/lib.py b/client/ayon_core/hosts/maya/api/lib.py index dac4c6a672..d3b3fd4d26 100644 --- a/client/ayon_core/hosts/maya/api/lib.py +++ b/client/ayon_core/hosts/maya/api/lib.py @@ -21,10 +21,7 @@ from maya.api import OpenMaya import ayon_api -from ayon_core.client import ( - get_last_versions, - get_representation_by_name, -) +from ayon_core.client import get_representation_by_name from ayon_core.settings import get_project_settings from ayon_core.pipeline import ( get_current_project_name, @@ -1985,14 +1982,13 @@ def assign_look(nodes, product_name="lookDefault"): product_entity["id"] for product_entity in product_entities_by_folder_id.values() } - last_version_docs = get_last_versions( + last_version_entities = ayon_api.get_last_versions( project_name, - subset_ids=product_ids, - fields=["_id", "name", "data.families"] + product_ids ) - last_version_docs_by_product_id = { - last_version_doc["parent"]: last_version_doc - for last_version_doc in last_version_docs + last_version_entities_by_product_id = { + last_version_entity["productId"]: last_version_entity + for last_version_entity in last_version_entities } for folder_id, asset_nodes in grouped.items(): @@ -2004,14 +2000,14 @@ def assign_look(nodes, product_name="lookDefault"): continue product_id = product_entity["id"] - last_version = last_version_docs_by_product_id.get(product_id) + last_version = last_version_entities_by_product_id.get(product_id) if not last_version: log.warning(( "Not found last version for product '{}' on folder with id {}" ).format(product_name, folder_id)) continue - families = last_version.get("data", {}).get("families") or [] + families = last_version.get("attrib", {}).get("families") or [] if "look" not in families: log.warning(( "Last version for product '{}' on folder with id {}" @@ -2020,9 +2016,9 @@ def assign_look(nodes, product_name="lookDefault"): continue log.debug("Assigning look '{}' ".format( - product_name, last_version["name"])) + product_name, last_version["version"])) - assign_look_by_version(asset_nodes, last_version["_id"]) + assign_look_by_version(asset_nodes, last_version["id"]) def apply_shaders(relationships, shadernodes, nodes): diff --git a/client/ayon_core/hosts/maya/api/setdress.py b/client/ayon_core/hosts/maya/api/setdress.py index e070130e15..a69bf8d39b 100644 --- a/client/ayon_core/hosts/maya/api/setdress.py +++ b/client/ayon_core/hosts/maya/api/setdress.py @@ -11,8 +11,6 @@ import ayon_api from maya import cmds from ayon_core.client import ( - get_version_by_name, - get_last_version_by_subset_id, get_representation_by_id, get_representation_by_name, get_representation_parents, @@ -298,26 +296,27 @@ def update_package_version(container, version): assert current_representation is not None, "This is a bug" ( - version_doc, + version_entity, product_entity, folder_entity, project_entity ) = get_representation_parents(project_name, current_representation) if version == -1: - new_version = get_last_version_by_subset_id( + new_version = ayon_api.get_last_version_by_product_id( project_name, product_entity["id"] ) else: - new_version = get_version_by_name( + new_version = ayon_api.get_version_by_name( project_name, version, product_entity["id"] ) - assert new_version is not None, "This is a bug" + if new_version is None: + raise ValueError("Version not found: {}".format(version)) # Get the new representation (new file) new_representation = get_representation_by_name( - project_name, current_representation["name"], new_version["_id"] + project_name, current_representation["name"], new_version["id"] ) # TODO there is 'get_representation_context' to get the context which # could be possible to use here @@ -325,7 +324,7 @@ def update_package_version(container, version): "project": project_entity, "folder": folder_entity, "product": product_entity, - "version": version_doc, + "version": version_entity, "representation": new_representation, } update_package(container, new_context) diff --git a/client/ayon_core/hosts/maya/tools/mayalookassigner/app.py b/client/ayon_core/hosts/maya/tools/mayalookassigner/app.py index 5158542a8f..44d8dfda21 100644 --- a/client/ayon_core/hosts/maya/tools/mayalookassigner/app.py +++ b/client/ayon_core/hosts/maya/tools/mayalookassigner/app.py @@ -2,10 +2,10 @@ import sys import time import logging +import ayon_api from qtpy import QtWidgets, QtCore from ayon_core import style -from ayon_core.client import get_last_version_by_subset_id from ayon_core.pipeline import get_current_project_name from ayon_core.tools.utils.lib import qt_app_context from ayon_core.hosts.maya.api.lib import ( @@ -240,8 +240,8 @@ class MayaLookAssignerWindow(QtWidgets.QWidget): continue # Get the latest version of this asset's look product - version = get_last_version_by_subset_id( - project_name, assign_look["_id"], fields=["_id"] + version_entity = ayon_api.get_last_version_by_product_id( + project_name, assign_look["id"], fields={"id"} ) product_name = assign_look["name"] @@ -283,7 +283,9 @@ class MayaLookAssignerWindow(QtWidgets.QWidget): # Assign look if nodes: - assign_look_by_version(nodes, version_id=version["_id"]) + assign_look_by_version( + nodes, version_id=version_entity["id"] + ) end = time.time() diff --git a/client/ayon_core/hosts/maya/tools/mayalookassigner/arnold_standin.py b/client/ayon_core/hosts/maya/tools/mayalookassigner/arnold_standin.py index bd2f0baddf..a20880dffc 100644 --- a/client/ayon_core/hosts/maya/tools/mayalookassigner/arnold_standin.py +++ b/client/ayon_core/hosts/maya/tools/mayalookassigner/arnold_standin.py @@ -4,10 +4,11 @@ from collections import defaultdict import logging from maya import cmds +import ayon_api from ayon_core.pipeline import get_current_project_name -from ayon_core.client import get_last_version_by_subset_name from ayon_core.hosts.maya import api + from . import lib from .alembic import get_alembic_ids_cache from .usd import is_usd_lib_supported, get_usd_ids_cache @@ -146,20 +147,21 @@ def assign_look(standin, product_name): for folder_id, node_ids in node_ids_by_folder_id.items(): # Get latest look version - version = get_last_version_by_subset_name( + version_entity = ayon_api.get_last_version_by_product_name( project_name, - subset_name=product_name, - asset_id=folder_id, - fields=["_id"] + product_name, + folder_id, + fields={"id"} ) - if not version: + if not version_entity: log.info("Didn't find last version for product name {}".format( product_name )) continue + version_id = version_entity["id"] - relationships = lib.get_look_relationships(version["_id"]) - shader_nodes, container_node = lib.load_look(version["_id"]) + relationships = lib.get_look_relationships(version_id) + shader_nodes, container_node = lib.load_look(version_id) namespace = shader_nodes[0].split(":")[0] # Get only the node ids and paths related to this folder diff --git a/client/ayon_core/hosts/maya/tools/mayalookassigner/vray_proxies.py b/client/ayon_core/hosts/maya/tools/mayalookassigner/vray_proxies.py index df74dcd217..74cdbeb7d4 100644 --- a/client/ayon_core/hosts/maya/tools/mayalookassigner/vray_proxies.py +++ b/client/ayon_core/hosts/maya/tools/mayalookassigner/vray_proxies.py @@ -4,8 +4,8 @@ from collections import defaultdict import logging from maya import cmds +import ayon_api -from ayon_core.client import get_last_version_by_subset_name from ayon_core.pipeline import get_current_project_name import ayon_core.hosts.maya.lib as maya_lib from . import lib @@ -73,27 +73,28 @@ def vrayproxy_assign_look(vrayproxy, product_name="lookDefault"): # Group by asset id so we run over the look per asset node_ids_by_asset_id = defaultdict(set) for node_id in nodes_by_id: - asset_id = node_id.split(":", 1)[0] - node_ids_by_asset_id[asset_id].add(node_id) + folder_id = node_id.split(":", 1)[0] + node_ids_by_asset_id[folder_id].add(node_id) project_name = get_current_project_name() - for asset_id, node_ids in node_ids_by_asset_id.items(): + for folder_id, node_ids in node_ids_by_asset_id.items(): # Get latest look version - version = get_last_version_by_subset_name( + version_entity = ayon_api.get_last_version_by_product_name( project_name, - subset_name=product_name, - asset_id=asset_id, - fields=["_id"] + product_name, + folder_id, + fields={"id"} ) - if not version: + if not version_entity: print("Didn't find last version for product name {}".format( product_name )) continue + version_id = version_entity["id"] - relationships = lib.get_look_relationships(version["_id"]) - shadernodes, _ = lib.load_look(version["_id"]) + relationships = lib.get_look_relationships(version_id) + shadernodes, _ = lib.load_look(version_id) # Get only the node ids and paths related to this asset # And get the shader edits the look supplies diff --git a/client/ayon_core/hosts/nuke/api/lib.py b/client/ayon_core/hosts/nuke/api/lib.py index 3f2621fa6f..88e3583410 100644 --- a/client/ayon_core/hosts/nuke/api/lib.py +++ b/client/ayon_core/hosts/nuke/api/lib.py @@ -14,11 +14,7 @@ import nuke from qtpy import QtCore, QtWidgets import ayon_api -from ayon_core.client import ( - get_versions, - get_last_versions, - get_representations, -) +from ayon_core.client import get_representations from ayon_core.host import HostDirmap from ayon_core.tools.utils import host_tools @@ -864,19 +860,21 @@ def check_inventory_versions(): repre_docs_by_id[repre_id] = repre_doc version_ids.add(repre_doc["parent"]) - version_docs = get_versions( - project_name, version_ids, fields=["_id", "name", "parent"] + version_entities = ayon_api.get_versions( + project_name, + version_ids=version_ids, + fields={"id", "version", "productId"}, ) # Store versions by id and collect product ids - version_docs_by_id = {} + version_entities_by_id = {} product_ids = set() - for version_doc in version_docs: - version_docs_by_id[version_doc["_id"]] = version_doc - product_ids.add(version_doc["parent"]) + for version_entity in version_entities: + version_entities_by_id[version_entity["id"]] = version_entity + product_ids.add(version_entity["productId"]) # Query last versions based on product ids - last_versions_by_product_id = get_last_versions( - project_name, subset_ids=product_ids, fields=["_id", "parent"] + last_versions_by_product_id = ayon_api.get_last_versions( + project_name, product_ids=product_ids, fields={"id", "productId"} ) # Loop through collected container nodes and their representation ids @@ -892,18 +890,18 @@ def check_inventory_versions(): continue version_id = repre_doc["parent"] - version_doc = version_docs_by_id.get(version_id) - if not version_doc: + version_entity = version_entities_by_id.get(version_id) + if not version_entity: log.warning(( "Could not find the version on node \"{}\"" ).format(node.name())) continue # Get last version based on product id - product_id = version_doc["parent"] + product_id = version_entity["productId"] last_version = last_versions_by_product_id[product_id] # Check if last version is same as current version - if last_version["_id"] == version_doc["_id"]: + if last_version["id"] == version_entity["id"]: color_value = "0x4ecd25ff" else: color_value = "0xd84f20ff" diff --git a/client/ayon_core/hosts/photoshop/plugins/publish/collect_published_version.py b/client/ayon_core/hosts/photoshop/plugins/publish/collect_published_version.py index 5ea8276dea..84c9fa3e62 100644 --- a/client/ayon_core/hosts/photoshop/plugins/publish/collect_published_version.py +++ b/client/ayon_core/hosts/photoshop/plugins/publish/collect_published_version.py @@ -16,8 +16,8 @@ Provides: """ import pyblish.api +import ayon_api -from ayon_core.client import get_last_version_by_subset_name from ayon_core.pipeline.version_start import get_versioning_start @@ -44,12 +44,12 @@ class CollectPublishedVersion(pyblish.api.ContextPlugin): project_name = context.data["projectName"] folder_id = context.data["folderEntity"]["id"] - version_doc = get_last_version_by_subset_name( + version_entity = ayon_api.get_last_version_by_product_name( project_name, workfile_product_name, folder_id ) - if version_doc: - version_int = int(version_doc["name"]) + 1 + if version_entity: + version_int = int(version_entity["version"]) + 1 else: version_int = get_versioning_start( project_name, diff --git a/client/ayon_core/hosts/traypublisher/api/plugin.py b/client/ayon_core/hosts/traypublisher/api/plugin.py index 1039b570ee..257d01eb50 100644 --- a/client/ayon_core/hosts/traypublisher/api/plugin.py +++ b/client/ayon_core/hosts/traypublisher/api/plugin.py @@ -1,6 +1,5 @@ import ayon_api -from ayon_core.client import get_last_versions from ayon_core.lib.attribute_definitions import ( FileDef, BoolDef, @@ -181,10 +180,10 @@ class SettingsCreator(TrayPublishCreator): )) product_ids = {p["id"] for p in product_entities} - last_versions = get_last_versions( + last_versions = ayon_api.get_last_versions( self.project_name, product_ids, - fields=["name", "parent"]) + fields={"version", "productId"}) for product_entity in product_entities: product_id = product_entity["id"] @@ -194,7 +193,7 @@ class SettingsCreator(TrayPublishCreator): last_version = last_versions.get(product_id) version = 0 if last_version is not None: - version = last_version["name"] + version = last_version["version"] product_entities_by_folder_path[folder_path][product_name] += ( version ) diff --git a/client/ayon_core/modules/deadline/plugins/publish/submit_publish_cache_job.py b/client/ayon_core/modules/deadline/plugins/publish/submit_publish_cache_job.py index 1bf23f84a5..0561e0f65c 100644 --- a/client/ayon_core/modules/deadline/plugins/publish/submit_publish_cache_job.py +++ b/client/ayon_core/modules/deadline/plugins/publish/submit_publish_cache_job.py @@ -4,11 +4,11 @@ import os import json import re from copy import deepcopy -import requests +import requests +import ayon_api import pyblish.api -from ayon_core.client import get_last_version_by_subset_name from ayon_core.pipeline import publish from ayon_core.lib import EnumDef, is_in_tests from ayon_core.pipeline.version_start import get_versioning_start @@ -411,16 +411,16 @@ class ProcessSubmittedCacheJobOnFarm(pyblish.api.InstancePlugin, project_name = context.data["projectName"] host_name = context.data["hostName"] if not version: - folder_id = None + version_entity = None if folder_entity: - folder_id = folder_entity["id"] - version = get_last_version_by_subset_name( - project_name, - product_name, - asset_id=folder_id - ) - if version: - version = int(version["name"]) + 1 + version_entity = ayon_api.get_last_version_by_product_name( + project_name, + product_name, + folder_entity["id"] + ) + + if version_entity: + version = int(version_entity["version"]) + 1 else: version = get_versioning_start( project_name, diff --git a/client/ayon_core/modules/deadline/plugins/publish/submit_publish_job.py b/client/ayon_core/modules/deadline/plugins/publish/submit_publish_job.py index 3c78a95f1e..7a6abd5507 100644 --- a/client/ayon_core/modules/deadline/plugins/publish/submit_publish_job.py +++ b/client/ayon_core/modules/deadline/plugins/publish/submit_publish_job.py @@ -4,12 +4,12 @@ import os import json import re from copy import deepcopy + import requests import clique - +import ayon_api import pyblish.api -from ayon_core.client import get_last_version_by_subset_name from ayon_core.pipeline import publish from ayon_core.lib import EnumDef, is_in_tests from ayon_core.pipeline.version_start import get_versioning_start @@ -533,16 +533,16 @@ class ProcessSubmittedJobOnFarm(pyblish.api.InstancePlugin, project_name = context.data["projectName"] host_name = context.data["hostName"] if not version: - folder_id = None + version_entity = None if folder_entity: - folder_id = folder_entity["id"] - version = get_last_version_by_subset_name( - project_name, - product_name, - asset_id=folder_id - ) - if version: - version = int(version["name"]) + 1 + version_entity = ayon_api.get_last_version_by_product_name( + project_name, + product_name, + folder_entity["id"] + ) + + if version_entity: + version = int(version_entity["version"]) + 1 else: version = get_versioning_start( project_name,