mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-26 13:52:15 +01:00
Merge pull request #1868 from pypeclub/feature/filter_hosts_in_enum
Filter hosts in settings host-enum
This commit is contained in:
commit
f369392caa
3 changed files with 94 additions and 21 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import copy
|
||||
from .input_entities import InputEntity
|
||||
from .exceptions import EntitySchemaError
|
||||
from .lib import (
|
||||
|
|
@ -118,30 +119,43 @@ class HostsEnumEntity(BaseEnumEntity):
|
|||
implementation instead of application name.
|
||||
"""
|
||||
schema_types = ["hosts-enum"]
|
||||
all_host_names = [
|
||||
"aftereffects",
|
||||
"blender",
|
||||
"celaction",
|
||||
"fusion",
|
||||
"harmony",
|
||||
"hiero",
|
||||
"houdini",
|
||||
"maya",
|
||||
"nuke",
|
||||
"photoshop",
|
||||
"resolve",
|
||||
"tvpaint",
|
||||
"unreal",
|
||||
"standalonepublisher"
|
||||
]
|
||||
|
||||
def _item_initalization(self):
|
||||
self.multiselection = self.schema_data.get("multiselection", True)
|
||||
self.use_empty_value = self.schema_data.get(
|
||||
"use_empty_value", not self.multiselection
|
||||
)
|
||||
use_empty_value = False
|
||||
if not self.multiselection:
|
||||
use_empty_value = self.schema_data.get(
|
||||
"use_empty_value", use_empty_value
|
||||
)
|
||||
self.use_empty_value = use_empty_value
|
||||
|
||||
hosts_filter = self.schema_data.get("hosts_filter") or []
|
||||
self.hosts_filter = hosts_filter
|
||||
|
||||
custom_labels = self.schema_data.get("custom_labels") or {}
|
||||
|
||||
host_names = [
|
||||
"aftereffects",
|
||||
"blender",
|
||||
"celaction",
|
||||
"fusion",
|
||||
"harmony",
|
||||
"hiero",
|
||||
"houdini",
|
||||
"maya",
|
||||
"nuke",
|
||||
"photoshop",
|
||||
"resolve",
|
||||
"tvpaint",
|
||||
"unreal",
|
||||
"standalonepublisher"
|
||||
]
|
||||
host_names = copy.deepcopy(self.all_host_names)
|
||||
if hosts_filter:
|
||||
for host_name in tuple(host_names):
|
||||
if host_name not in hosts_filter:
|
||||
host_names.remove(host_name)
|
||||
|
||||
if self.use_empty_value:
|
||||
host_names.insert(0, "")
|
||||
# Add default label for empty value if not available
|
||||
|
|
@ -173,6 +187,44 @@ class HostsEnumEntity(BaseEnumEntity):
|
|||
# GUI attribute
|
||||
self.placeholder = self.schema_data.get("placeholder")
|
||||
|
||||
def schema_validations(self):
|
||||
if self.hosts_filter:
|
||||
enum_len = len(self.enum_items)
|
||||
if (
|
||||
enum_len == 0
|
||||
or (enum_len == 1 and self.use_empty_value)
|
||||
):
|
||||
joined_filters = ", ".join([
|
||||
'"{}"'.format(item)
|
||||
for item in self.hosts_filter
|
||||
])
|
||||
reason = (
|
||||
"All host names were removed after applying"
|
||||
" host filters. {}"
|
||||
).format(joined_filters)
|
||||
raise EntitySchemaError(self, reason)
|
||||
|
||||
invalid_filters = set()
|
||||
for item in self.hosts_filter:
|
||||
if item not in self.all_host_names:
|
||||
invalid_filters.add(item)
|
||||
|
||||
if invalid_filters:
|
||||
joined_filters = ", ".join([
|
||||
'"{}"'.format(item)
|
||||
for item in self.hosts_filter
|
||||
])
|
||||
expected_hosts = ", ".join([
|
||||
'"{}"'.format(item)
|
||||
for item in self.all_host_names
|
||||
])
|
||||
self.log.warning((
|
||||
"Host filters containt invalid host names:"
|
||||
" \"{}\" Expected values are {}"
|
||||
).format(joined_filters, expected_hosts))
|
||||
|
||||
super(HostsEnumEntity, self).schema_validations()
|
||||
|
||||
|
||||
class AppsEnumEntity(BaseEnumEntity):
|
||||
schema_types = ["apps-enum"]
|
||||
|
|
|
|||
|
|
@ -379,6 +379,9 @@ How output of the schema could look like on save:
|
|||
- multiselection can be allowed with setting key `"multiselection"` to `True` (Default: `False`)
|
||||
- it is possible to add empty value (represented with empty string) with setting `"use_empty_value"` to `True` (Default: `False`)
|
||||
- it is possible to set `"custom_labels"` for host names where key `""` is empty value (Default: `{}`)
|
||||
- to filter host names it is required to define `"hosts_filter"` which is list of host names that will be available
|
||||
- do not pass empty string if `use_empty_value` is enabled
|
||||
- ignoring host names would be more dangerous in some cases
|
||||
```
|
||||
{
|
||||
"key": "host",
|
||||
|
|
@ -389,7 +392,10 @@ How output of the schema could look like on save:
|
|||
"custom_labels": {
|
||||
"": "N/A",
|
||||
"nuke": "Nuke"
|
||||
}
|
||||
},
|
||||
"hosts_filter": [
|
||||
"nuke"
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,22 @@
|
|||
"type": "hosts-enum",
|
||||
"key": "hosts",
|
||||
"label": "Hosts",
|
||||
"multiselection": true
|
||||
"multiselection": true,
|
||||
"hosts_filter": [
|
||||
"aftereffects",
|
||||
"blender",
|
||||
"celaction",
|
||||
"fusion",
|
||||
"harmony",
|
||||
"hiero",
|
||||
"houdini",
|
||||
"maya",
|
||||
"nuke",
|
||||
"photoshop",
|
||||
"resolve",
|
||||
"tvpaint",
|
||||
"unreal"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "tasks",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue