From 2c410e3d5435d661861acab1ea4f93c7de3387aa Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 3 Feb 2023 12:08:08 +0100 Subject: [PATCH 1/4] gracefully skip if label is not set --- openpype/hosts/houdini/api/shelves.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/houdini/api/shelves.py b/openpype/hosts/houdini/api/shelves.py index 3ccab964cd..3a6534d0eb 100644 --- a/openpype/hosts/houdini/api/shelves.py +++ b/openpype/hosts/houdini/api/shelves.py @@ -152,9 +152,13 @@ def get_or_create_tool(tool_definition, shelf): Returns: hou.Tool: The tool updated or the new one """ - existing_tools = shelf.tools() - tool_label = tool_definition.get('label') + tool_label = tool_definition.get("label") + if not tool_label: + log.warning("Skipped shelf without label") + return + + existing_tools = shelf.tools() existing_tool = next( (tool for tool in existing_tools if tool.label() == tool_label), None From 2c17a9bb4e866c3e85127acba40ade4f34eafdf6 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 3 Feb 2023 12:08:20 +0100 Subject: [PATCH 2/4] fix mandatory keys --- openpype/hosts/houdini/api/shelves.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/houdini/api/shelves.py b/openpype/hosts/houdini/api/shelves.py index 3a6534d0eb..efbc0f5b04 100644 --- a/openpype/hosts/houdini/api/shelves.py +++ b/openpype/hosts/houdini/api/shelves.py @@ -66,7 +66,7 @@ def generate_shelves(): ) continue - mandatory_attributes = {'name', 'script'} + mandatory_attributes = {'label', 'script'} for tool_definition in shelf_definition.get('tools_list'): # We verify that the name and script attibutes of the tool # are set From 79e7b0e0d5052d5cb180b847fa20e2f2f04a6e3c Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 3 Feb 2023 12:08:47 +0100 Subject: [PATCH 3/4] check script path and gracefully skip if was not found or not set --- openpype/hosts/houdini/api/shelves.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openpype/hosts/houdini/api/shelves.py b/openpype/hosts/houdini/api/shelves.py index efbc0f5b04..f6295ddfe7 100644 --- a/openpype/hosts/houdini/api/shelves.py +++ b/openpype/hosts/houdini/api/shelves.py @@ -158,6 +158,11 @@ def get_or_create_tool(tool_definition, shelf): log.warning("Skipped shelf without label") return + script_path = tool_definition["script"] + if not script_path or not os.path.exists(script_path): + log.warning("This path doesn't exist - {}".format(script_path)) + return + existing_tools = shelf.tools() existing_tool = next( (tool for tool in existing_tools if tool.label() == tool_label), From 4c502ffe85af5d66ea2638d839b4487d0dfb2a42 Mon Sep 17 00:00:00 2001 From: Jakub Trllo Date: Fri, 3 Feb 2023 12:14:42 +0100 Subject: [PATCH 4/4] change how shelves are created --- openpype/hosts/houdini/api/shelves.py | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/openpype/hosts/houdini/api/shelves.py b/openpype/hosts/houdini/api/shelves.py index f6295ddfe7..ebd668e9e4 100644 --- a/openpype/hosts/houdini/api/shelves.py +++ b/openpype/hosts/houdini/api/shelves.py @@ -1,4 +1,5 @@ import os +import re import logging import platform @@ -168,24 +169,16 @@ def get_or_create_tool(tool_definition, shelf): (tool for tool in existing_tools if tool.label() == tool_label), None ) + + with open(script_path) as stream: + script = stream.read() + + tool_definition["script"] = script + if existing_tool: - tool_definition.pop('name', None) - tool_definition.pop('label', None) + tool_definition.pop("label", None) existing_tool.setData(**tool_definition) return existing_tool - tool_name = tool_label.replace(' ', '_').lower() - - if not os.path.exists(tool_definition['script']): - log.warning( - "This path doesn't exist - {}".format(tool_definition['script']) - ) - return - - with open(tool_definition['script']) as f: - script = f.read() - tool_definition.update({'script': script}) - - new_tool = hou.shelves.newTool(name=tool_name, **tool_definition) - - return new_tool + tool_name = re.sub(r"[^\w\d]+", "_", tool_label).lower() + return hou.shelves.newTool(name=tool_name, **tool_definition)