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

Filter hosts in settings host-enum #1868

Merged
merged 7 commits into from
Jul 28, 2021
Merged
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
90 changes: 71 additions & 19 deletions openpype/settings/entities/enum_entity.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
from .input_entities import InputEntity
from .exceptions import EntitySchemaError
from .lib import (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -173,6 +187,44 @@ def _item_initalization(self):
# 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"]
Expand Down
8 changes: 7 additions & 1 deletion openpype/settings/entities/schemas/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -389,7 +392,10 @@ How output of the schema could look like on save:
"custom_labels": {
"": "N/A",
"nuke": "Nuke"
}
},
"hosts_filter": [
"nuke"
]
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down