From 4b15f2795935a1ded636452fce8e165aee8ef7cd Mon Sep 17 00:00:00 2001 From: Cyprien CAILLOT Date: Wed, 11 Sep 2024 17:07:24 +0200 Subject: [PATCH 1/2] Enhancement: Add settings entities widgets for deadline pools and limits plugin --- openpype/modules/deadline/__init__.py | 6 + openpype/modules/deadline/utils.py | 20 +++ openpype/settings/entities/__init__.py | 4 + openpype/settings/entities/enum_entity.py | 156 +++++++++++++++++++++- 4 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 openpype/modules/deadline/utils.py diff --git a/openpype/modules/deadline/__init__.py b/openpype/modules/deadline/__init__.py index 5631e501d81..ef3f82e4911 100644 --- a/openpype/modules/deadline/__init__.py +++ b/openpype/modules/deadline/__init__.py @@ -1,6 +1,12 @@ from .deadline_module import DeadlineModule +from .utils import ( + get_deadline_limit_groups +) + __all__ = ( "DeadlineModule", + + "get_deadline_limit_groups" ) diff --git a/openpype/modules/deadline/utils.py b/openpype/modules/deadline/utils.py new file mode 100644 index 00000000000..e61a8d74a2d --- /dev/null +++ b/openpype/modules/deadline/utils.py @@ -0,0 +1,20 @@ +from openpype.pipeline.context_tools import ( + _get_modules_manager +) + + +def get_deadline_limit_groups(deadline_enabled, deadline_url, log): + manager = _get_modules_manager() + deadline_module = manager.modules_by_name["deadline"] + + limit_groups = [] + if deadline_enabled and deadline_url: + requested_arguments = {"NamesOnly": True} + limit_groups = deadline_module.get_deadline_data( + deadline_url, + "limitgroups", + log=log, + **requested_arguments + ) + + return limit_groups diff --git a/openpype/settings/entities/__init__.py b/openpype/settings/entities/__init__.py index 00db2b33a7d..4ff06a9a744 100644 --- a/openpype/settings/entities/__init__.py +++ b/openpype/settings/entities/__init__.py @@ -106,6 +106,8 @@ ToolsEnumEntity, TaskTypeEnumEntity, DeadlineUrlEnumEntity, + DeadlineLimitsPluginEnumEntity, + DeadlinePoolsEnumEntity, AnatomyTemplatesEnumEntity, ShotgridUrlEnumEntity, RoyalRenderRootEnumEntity @@ -170,6 +172,8 @@ "ToolsEnumEntity", "TaskTypeEnumEntity", "DeadlineUrlEnumEntity", + "DeadlineLimitsPluginEnumEntity", + "DeadlinePoolsEnumEntity", "ShotgridUrlEnumEntity", "RoyalRenderRootEnumEntity", "AnatomyTemplatesEnumEntity", diff --git a/openpype/settings/entities/enum_entity.py b/openpype/settings/entities/enum_entity.py index dcbcb9cb35a..0a091df40fe 100644 --- a/openpype/settings/entities/enum_entity.py +++ b/openpype/settings/entities/enum_entity.py @@ -1,10 +1,15 @@ import abc -import six + import copy + +import requests + from .input_entities import InputEntity from .exceptions import EntitySchemaError from .lib import NOT_SET, STRING_TYPE +from openpype.settings import get_system_settings + class BaseEnumEntity(InputEntity): def _item_initialization(self): @@ -540,6 +545,155 @@ def _get_enum_values(self): return enum_items_list, valid_keys +class DeadlineLimitGroupEnumEntity(BaseEnumEntity): + schema_types = ["deadline-limits-group-enum"] + + def _item_initialization(self): + self.multiselection = self.schema_data.get("multiselection", True) + if self.multiselection: + self.valid_value_types = (list,) + self.value_on_not_set = [] + else: + self.valid_value_types = (STRING_TYPE,) + self.value_on_not_set = "" + + self.enum_items = [] + self.valid_keys = set() + self.placeholder = None + + def _get_enum_values(self): + # Import here to avoid circular import + from openpype.modules.deadline import get_deadline_limit_groups + + modules_system_settings = get_system_settings()["modules"] + deadline_enabled = modules_system_settings["deadline"]["enabled"] + if not deadline_enabled: + return [], set() + + deadline_url = modules_system_settings["deadline"]["deadline_urls"].get("default", "") # noqa + + try: + requests.get(deadline_url) + limit_groups = get_deadline_limit_groups( + deadline_enabled, + deadline_url, + self.log + ) + except requests.exceptions.ConnectionError: + limit_groups = None + + if not limit_groups: + return [], set() + + valid_keys = set() + enum_items = [] + for group_name in limit_groups: + enum_items.append({group_name: group_name}) + valid_keys.add(group_name) + + return enum_items, valid_keys + + def _convert_value_for_current_state(self, source_value): + if self.multiselection: + output = [] + for key in source_value: + if key in self.valid_keys: + output.append(key) + return output + + if source_value not in self.valid_keys: + # Take first item from enum items + for item in self.enum_items: + for key in item.keys(): + source_value = key + break + return source_value + + def set_override_state(self, *args, **kwargs): + super(DeadlineLimitGroupEnumEntity, self).set_override_state(*args, **kwargs) + + self.enum_items, self.valid_keys = self._get_enum_values() + + if self.multiselection: + new_value = [] + for key in self._current_value: + if key in self.valid_keys: + new_value.append(key) + + if self._current_value != new_value: + self.set(new_value) + else: + if not self.enum_items: + self.valid_keys.add("") + self.enum_items.append({"": "< Empty >"}) + + for item in self.enum_items: + for key in item.keys(): + value_on_not_set = key + break + + self.value_on_not_set = value_on_not_set + if ( + self._current_value is NOT_SET + or self._current_value not in self.valid_keys + ): + self.set(value_on_not_set) + + +class DeadlinePoolEnumEntity(DynamicEnumEntity): + schema_types = ["deadline-pool-enum"] + + def _item_initialization(self): + self.multiselection = False + self.valid_value_types = (STRING_TYPE,) + self.value_on_not_set = "" + self.enum_items = [] + self.valid_keys = set() + self.placeholder = None + + def _get_enum_values(self): + # Import here to avoid circular import + from openpype.pipeline.context_tools import _get_modules_manager + + modules_system_settings = get_system_settings()["modules"] + deadline_enabled = modules_system_settings["deadline"]["enabled"] + if not deadline_enabled: + return [], set() + + deadline_url = modules_system_settings["deadline"]["deadline_urls"].get("default", "") # noqa + manager = _get_modules_manager() + deadline_module = manager.modules_by_name["deadline"] + try: + requests.get(deadline_url) + pools = deadline_module.get_deadline_pools(deadline_url, self.log) + except requests.exceptions.ConnectionError: + pools = None + + if not pools: + return [], set() + + valid_keys = set() + enum_items = [] + for plugin_name in pools: + enum_items.append({plugin_name: plugin_name}) + valid_keys.add(plugin_name) + + return enum_items, valid_keys + + def _convert_value_for_current_state(self, source_value): + + if source_value not in self.valid_keys: + # Take first item from enum items + for item in self.enum_items: + for key in item.keys(): + source_value = key + break + return source_value + + def set_override_state(self, *args, **kwargs): + super(DeadlinePoolEnumEntity, self).set_override_state(*args, **kwargs) + + class RoyalRenderRootEnumEntity(DynamicEnumEntity): schema_types = ["rr_root-enum"] From 59beef5a8a5dd1c646197de188ffb6ae429a8804 Mon Sep 17 00:00:00 2001 From: Cyprien CAILLOT Date: Wed, 11 Sep 2024 17:12:41 +0200 Subject: [PATCH 2/2] Enhancement: Add settings entities widgets for deadline pools and limits plugin --- openpype/settings/entities/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openpype/settings/entities/__init__.py b/openpype/settings/entities/__init__.py index 4ff06a9a744..67fe1c1a8f5 100644 --- a/openpype/settings/entities/__init__.py +++ b/openpype/settings/entities/__init__.py @@ -106,8 +106,8 @@ ToolsEnumEntity, TaskTypeEnumEntity, DeadlineUrlEnumEntity, - DeadlineLimitsPluginEnumEntity, - DeadlinePoolsEnumEntity, + DeadlineLimitGroupEnumEntity, + DeadlinePoolEnumEntity, AnatomyTemplatesEnumEntity, ShotgridUrlEnumEntity, RoyalRenderRootEnumEntity @@ -172,8 +172,8 @@ "ToolsEnumEntity", "TaskTypeEnumEntity", "DeadlineUrlEnumEntity", - "DeadlineLimitsPluginEnumEntity", - "DeadlinePoolsEnumEntity", + "DeadlineLimitGroupEnumEntity", + "DeadlinePoolEnumEntity", "ShotgridUrlEnumEntity", "RoyalRenderRootEnumEntity", "AnatomyTemplatesEnumEntity",