From 1dd1a3030591a4d0a5a6f3c9f18f2a7cbf8e50c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A0=20Serra=20Arrizabalaga?= Date: Wed, 10 Jul 2024 20:03:10 +0200 Subject: [PATCH 1/4] Refactor check_inventory_versions to use existing container functions and avoid issue when finding OpenPype invalid containers --- client/ayon_nuke/api/lib.py | 97 +++++++------------------------------ 1 file changed, 17 insertions(+), 80 deletions(-) diff --git a/client/ayon_nuke/api/lib.py b/client/ayon_nuke/api/lib.py index 9055212..b220c7f 100644 --- a/client/ayon_nuke/api/lib.py +++ b/client/ayon_nuke/api/lib.py @@ -33,6 +33,7 @@ from ayon_core.pipeline.template_data import get_template_data_with_names from ayon_core.pipeline import ( Anatomy, + registered_host, get_current_host_name, get_current_project_name, get_current_folder_path, @@ -40,6 +41,7 @@ AYON_INSTANCE_ID, AVALON_INSTANCE_ID, ) +from ayon_core.pipeline.load import filter_containers from ayon_core.pipeline.context_tools import ( get_current_context_custom_workfile_template ) @@ -810,89 +812,24 @@ def check_inventory_versions(): and check if the node is having actual version. If not then it will color it to red. """ - from .pipeline import parse_container - - # get all Loader nodes by avalon attribute metadata - node_with_repre_id = [] - repre_ids = set() - # Find all containers and collect it's node and representation ids - for node in nuke.allNodes(): - container = parse_container(node) - - if container: - node = nuke.toNode(container["objectName"]) - avalon_knob_data = read_avalon_data(node) - repre_id = avalon_knob_data["representation"] - - repre_ids.add(repre_id) - node_with_repre_id.append((node, repre_id)) - - # Skip if nothing was found - if not repre_ids: - return - + host = registered_host() + containers = host.get_containers() project_name = get_current_project_name() - # Find representations based on found containers - repre_entities = ayon_api.get_representations( - project_name, - representation_ids=repre_ids, - fields={"id", "versionId"} - ) - # Store representations by id and collect version ids - repre_entities_by_id = {} - version_ids = set() - for repre_entity in repre_entities: - # Use stringed representation id to match value in containers - repre_id = repre_entity["id"] - repre_entities_by_id[repre_id] = repre_entity - version_ids.add(repre_entity["versionId"]) - - 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_entities_by_id = {} - product_ids = set() - 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 = ayon_api.get_last_versions( - project_name, product_ids=product_ids, fields={"id", "productId"} - ) - - # Loop through collected container nodes and their representation ids - for item in node_with_repre_id: - # Some python versions of nuke can't unfold tuple in for loop - node, repre_id = item - repre_entity = repre_entities_by_id.get(repre_id) - # Failsafe for not finding the representation. - if not repre_entity: - log.warning(( - "Could not find the representation on node \"{}\"" - ).format(node.name())) - continue - version_id = repre_entity["versionId"] - 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 + category_colors = { + "latest": "0x4ecd25ff", + "outdated": "0xd84f20ff", + "invalid": "0xff0000ff", + "not_found": "0xffff00ff", + } - # Get last version based on product id - 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_entity["id"]: - color_value = "0x4ecd25ff" - else: - color_value = "0xd84f20ff" - node["tile_color"].setValue(int(color_value, 16)) + filtered_containers = filter_containers(containers, project_name) + for category, containers in filtered_containers._asdict().items(): + container_color = category_colors.get(category) or category_colors["not_found"] + for container in containers: + container["node"]["tile_color"].setValue( + int(container_color, 16) + ) def writes_version_sync(): From 7831fc879c0e50fe83864e86d89279556de61c7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A0=20Serra=20Arrizabalaga?= Date: Wed, 10 Jul 2024 23:25:36 +0200 Subject: [PATCH 2/4] Address feedback from PR Co-authored-by: Roy Nieterau --- client/ayon_nuke/api/lib.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/ayon_nuke/api/lib.py b/client/ayon_nuke/api/lib.py index b220c7f..175f906 100644 --- a/client/ayon_nuke/api/lib.py +++ b/client/ayon_nuke/api/lib.py @@ -825,11 +825,12 @@ def check_inventory_versions(): filtered_containers = filter_containers(containers, project_name) for category, containers in filtered_containers._asdict().items(): - container_color = category_colors.get(category) or category_colors["not_found"] + if category not in category_colors: + continue + color = category_colors[category] + color = int(color, 16) # convert hex to nuke tile color int for container in containers: - container["node"]["tile_color"].setValue( - int(container_color, 16) - ) + container["node"]["tile_color"].setValue(color) def writes_version_sync(): From e21ad5d947fe027b6b79aa06cdbd7f0911269c13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A0=20Serra=20Arrizabalaga?= Date: Wed, 10 Jul 2024 23:26:28 +0200 Subject: [PATCH 3/4] Update docstring --- client/ayon_nuke/api/lib.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/ayon_nuke/api/lib.py b/client/ayon_nuke/api/lib.py index 175f906..e43e035 100644 --- a/client/ayon_nuke/api/lib.py +++ b/client/ayon_nuke/api/lib.py @@ -804,13 +804,10 @@ def on_script_load(): def check_inventory_versions(): - """ - Actual version identifier of Loaded containers + """Update loaded container nodes' colors based on version state. - Any time this function is run it will check all nodes and filter only - Loader nodes for its version. It will get all versions from database - and check if the node is having actual version. If not then it will color - it to red. + This will group containers by their version to outdated, not found, + invalid or latest and colorize the nodes based on the category. """ host = registered_host() containers = host.get_containers() From 2409a3b319d4514c2d7ba2257cc877564ef5dd50 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 1 Aug 2024 17:18:48 +0200 Subject: [PATCH 4/4] Add loader category colors to constants and update lib usage. - Added loader category colors to constants file. - Updated lib file to use the new loader category colors constant. --- client/ayon_nuke/api/constants.py | 6 ++++++ client/ayon_nuke/api/lib.py | 16 ++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/client/ayon_nuke/api/constants.py b/client/ayon_nuke/api/constants.py index 1101997..fa39626 100644 --- a/client/ayon_nuke/api/constants.py +++ b/client/ayon_nuke/api/constants.py @@ -2,3 +2,9 @@ ASSIST = bool(os.getenv("NUKEASSIST")) +LOADER_CATEGORY_COLORS = { + "latest": "0x4ecd25ff", + "outdated": "0xd84f20ff", + "invalid": "0xff0000ff", + "not_found": "0xffff00ff", +} diff --git a/client/ayon_nuke/api/lib.py b/client/ayon_nuke/api/lib.py index e43e035..d15a7dd 100644 --- a/client/ayon_nuke/api/lib.py +++ b/client/ayon_nuke/api/lib.py @@ -50,7 +50,10 @@ ) from ayon_core.pipeline.workfile import BuildWorkfile from . import gizmo_menu -from .constants import ASSIST +from .constants import ( + ASSIST, + LOADER_CATEGORY_COLORS, +) from .workio import save_file from .utils import get_node_outputs @@ -813,18 +816,11 @@ def check_inventory_versions(): containers = host.get_containers() project_name = get_current_project_name() - category_colors = { - "latest": "0x4ecd25ff", - "outdated": "0xd84f20ff", - "invalid": "0xff0000ff", - "not_found": "0xffff00ff", - } - filtered_containers = filter_containers(containers, project_name) for category, containers in filtered_containers._asdict().items(): - if category not in category_colors: + if category not in LOADER_CATEGORY_COLORS: continue - color = category_colors[category] + color = LOADER_CATEGORY_COLORS[category] color = int(color, 16) # convert hex to nuke tile color int for container in containers: container["node"]["tile_color"].setValue(color)