Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

[QUAD] Enhancement: Add settings entities/widgets for deadline pools and limits plugin #6351

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions openpype/modules/deadline/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from .deadline_module import DeadlineModule

from .utils import (
get_deadline_limit_groups
)


__all__ = (
"DeadlineModule",

"get_deadline_limit_groups"
)
20 changes: 20 additions & 0 deletions openpype/modules/deadline/utils.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions openpype/settings/entities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@
ToolsEnumEntity,
TaskTypeEnumEntity,
DeadlineUrlEnumEntity,
DeadlineLimitGroupEnumEntity,
DeadlinePoolEnumEntity,
AnatomyTemplatesEnumEntity,
ShotgridUrlEnumEntity,
RoyalRenderRootEnumEntity
Expand Down Expand Up @@ -170,6 +172,8 @@
"ToolsEnumEntity",
"TaskTypeEnumEntity",
"DeadlineUrlEnumEntity",
"DeadlineLimitGroupEnumEntity",
"DeadlinePoolEnumEntity",
"ShotgridUrlEnumEntity",
"RoyalRenderRootEnumEntity",
"AnatomyTemplatesEnumEntity",
Expand Down
156 changes: 155 additions & 1 deletion openpype/settings/entities/enum_entity.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (85 > 79 characters)


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"]

Expand Down
Loading