From ddd998f417c1f90266319c9152bfe6f639c9e877 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Tue, 28 May 2024 16:46:41 +0200 Subject: [PATCH 01/31] AY-5539 - new Settings for filtering of creators --- server/settings/tools.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/server/settings/tools.py b/server/settings/tools.py index fb8430a71c..6d0c133511 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -35,6 +35,22 @@ class ProductNameProfile(BaseSettingsModel): template: str = SettingsField("", title="Template") +class FilterCreatorProfile(BaseSettingsModel): + """Provide list of allowed Creator identifiers for context""" + + _layout = "expanded" + hosts: list[str] = SettingsField(default_factory=list, title="Hosts") + task_types: list[str] = SettingsField( + default_factory=list, + title="Task types", + enum_resolver=task_types_enum + ) + task_names: list[str] = SettingsField(default_factory=list, + title="Task names") + creator_identifiers: list[str] = SettingsField( + "", title="Allowed Creator Identifiers") + + class CreatorToolModel(BaseSettingsModel): # TODO this was dynamic dictionary '{name: task_names}' product_types_smart_select: list[ProductTypeSmartSelectModel] = ( @@ -48,6 +64,11 @@ class CreatorToolModel(BaseSettingsModel): title="Product name profiles" ) + filter_creator_profiles: list[FilterCreatorProfile] = SettingsField( + default_factory=list, + title="Filter creator profiles" + ) + @validator("product_types_smart_select") def validate_unique_name(cls, value): ensure_unique_names(value) @@ -404,7 +425,8 @@ class GlobalToolsModel(BaseSettingsModel): "tasks": [], "template": "SK_{folder[name]}{variant}" } - ] + ], + "filter_creator_profiles": [] }, "Workfiles": { "workfile_template_profiles": [ From cd11db27aa316c669f0963ac0cec1b2a612362e8 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Tue, 28 May 2024 16:47:42 +0200 Subject: [PATCH 02/31] AY-5539 - use configured profiles to filter creators --- client/ayon_core/tools/publisher/control.py | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index ede772b917..9ffa33ce5c 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -39,6 +39,9 @@ ) from ayon_core.pipeline.publish import get_publish_instance_label from ayon_core.tools.common_models import HierarchyModel +from ayon_core.settings import get_project_settings +from ayon_core.lib.profiles_filtering import filter_profiles +from ayon_core.pipeline.context_tools import get_current_task_entity # Define constant for plugin orders offset PLUGIN_ORDER_OFFSET = 0.5 @@ -1827,8 +1830,13 @@ def _reset_plugins(self): def _collect_creator_items(self): # TODO add crashed initialization of create plugins to report output = {} + allowed_creator_identifiers = self._get_allowed_creator_identifiers() for identifier, creator in self._create_context.creators.items(): try: + if (allowed_creator_identifiers and + identifier not in allowed_creator_identifiers): + self.log.debug(f"{identifier} not allowed for context") + continue output[identifier] = CreatorItem.from_creator(creator) except Exception: self.log.error( @@ -1839,6 +1847,35 @@ def _collect_creator_items(self): return output + def _get_allowed_creator_identifiers(self): + """Provide configured creator identifier in this context + + If no profile provided for current context, it shows all creators + """ + proj_settings = get_project_settings(self.project_name) + filter_creator_profiles = ( + proj_settings + ["core"] + ["tools"] + ["creator"] + ["filter_creator_profiles"] + ) + task_type = get_current_task_entity()["taskType"] + filtering_criteria = { + "task_names": self.current_task_name, + "task_types": task_type, + "hosts": self._create_context.host_name + } + profile = filter_profiles( + filter_creator_profiles, + filtering_criteria, + logger=self.log + ) + allowed_creator_identifiers = [] + if profile: + allowed_creator_identifiers = profile["creator_identifiers"] + return allowed_creator_identifiers + def _reset_instances(self): """Reset create instances.""" if self._resetting_instances: From 2cf7f36f9b5820b35684d3f66406d4256bf2f919 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Tue, 28 May 2024 16:50:32 +0200 Subject: [PATCH 03/31] AY-5539 - do not use profiles for traypublisher --- client/ayon_core/tools/publisher/control.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 9ffa33ce5c..b116b4138b 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1852,6 +1852,10 @@ def _get_allowed_creator_identifiers(self): If no profile provided for current context, it shows all creators """ + allowed_creator_identifiers = [] + if self._create_context.host_name == "traypublisher": + # no real context known + return allowed_creator_identifiers proj_settings = get_project_settings(self.project_name) filter_creator_profiles = ( proj_settings @@ -1871,7 +1875,7 @@ def _get_allowed_creator_identifiers(self): filtering_criteria, logger=self.log ) - allowed_creator_identifiers = [] + if profile: allowed_creator_identifiers = profile["creator_identifiers"] return allowed_creator_identifiers From ce13e2ee027c620f04baf7c9207e561dfc30807a Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Tue, 28 May 2024 16:58:11 +0200 Subject: [PATCH 04/31] AY-5539 - provide better method signature Should be used for unittests --- client/ayon_core/tools/publisher/control.py | 28 +++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index b116b4138b..7753804911 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1830,7 +1830,13 @@ def _reset_plugins(self): def _collect_creator_items(self): # TODO add crashed initialization of create plugins to report output = {} - allowed_creator_identifiers = self._get_allowed_creator_identifiers() + allowed_creator_identifiers = self._get_allowed_creator_identifiers( + self.project_name, + self._create_context.host_name, + self.current_task_name, + get_current_task_entity()["taskType"], + self.log + ) for identifier, creator in self._create_context.creators.items(): try: if (allowed_creator_identifiers and @@ -1847,16 +1853,23 @@ def _collect_creator_items(self): return output - def _get_allowed_creator_identifiers(self): + def _get_allowed_creator_identifiers( + self, + project_name, + host_name, + task_name, + task_type, + log=None + ): """Provide configured creator identifier in this context If no profile provided for current context, it shows all creators """ allowed_creator_identifiers = [] - if self._create_context.host_name == "traypublisher": + if host_name == "traypublisher": # no real context known return allowed_creator_identifiers - proj_settings = get_project_settings(self.project_name) + proj_settings = get_project_settings(project_name) filter_creator_profiles = ( proj_settings ["core"] @@ -1864,16 +1877,15 @@ def _get_allowed_creator_identifiers(self): ["creator"] ["filter_creator_profiles"] ) - task_type = get_current_task_entity()["taskType"] filtering_criteria = { - "task_names": self.current_task_name, + "task_names": task_name, "task_types": task_type, - "hosts": self._create_context.host_name + "hosts": host_name } profile = filter_profiles( filter_creator_profiles, filtering_criteria, - logger=self.log + logger=log ) if profile: From 170b1ab9dce32804c737b4b3e5d316fb8b7b56e8 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 12:12:56 +0200 Subject: [PATCH 05/31] Fix default factory Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- server/settings/tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/settings/tools.py b/server/settings/tools.py index 6d0c133511..5587e38ed1 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -48,7 +48,8 @@ class FilterCreatorProfile(BaseSettingsModel): task_names: list[str] = SettingsField(default_factory=list, title="Task names") creator_identifiers: list[str] = SettingsField( - "", title="Allowed Creator Identifiers") + default_factory=list, + title="Allowed Creator Identifiers") class CreatorToolModel(BaseSettingsModel): From ea626e125769e91ab2afa6b5fe01dcddecf5159c Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 12:13:10 +0200 Subject: [PATCH 06/31] Fix formatting Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/tools/publisher/control.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 7753804911..9ea1efecba 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1839,8 +1839,10 @@ def _collect_creator_items(self): ) for identifier, creator in self._create_context.creators.items(): try: - if (allowed_creator_identifiers and - identifier not in allowed_creator_identifiers): + if ( + allowed_creator_identifiers is not None + and identifier not in allowed_creator_identifiers + ): self.log.debug(f"{identifier} not allowed for context") continue output[identifier] = CreatorItem.from_creator(creator) From 34041b3a1d3c3419b024f0b458d5eb1a76bc8d1f Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 12:13:23 +0200 Subject: [PATCH 07/31] Fix formatting Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/tools/publisher/control.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 9ea1efecba..fa8236e64f 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1856,12 +1856,12 @@ def _collect_creator_items(self): return output def _get_allowed_creator_identifiers( - self, - project_name, - host_name, - task_name, - task_type, - log=None + self, + project_name, + host_name, + task_name, + task_type, + log=None ): """Provide configured creator identifier in this context From 5e95565d25eb6f5511e4a109c4eb5c527cff9689 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 12:15:05 +0200 Subject: [PATCH 08/31] Fix formatting Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- server/settings/tools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/settings/tools.py b/server/settings/tools.py index 5587e38ed1..37b0ddfd59 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -45,8 +45,9 @@ class FilterCreatorProfile(BaseSettingsModel): title="Task types", enum_resolver=task_types_enum ) - task_names: list[str] = SettingsField(default_factory=list, - title="Task names") + task_names: list[str] = SettingsField( + default_factory=list, + title="Task names") creator_identifiers: list[str] = SettingsField( default_factory=list, title="Allowed Creator Identifiers") From 719e5aa56bb3cc84471509631bb6b75aa18b8b17 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 13:16:05 +0200 Subject: [PATCH 09/31] AY-5539 - remove explicit check for traypublisher Safely return task_type only if task_entity exits. --- client/ayon_core/tools/publisher/control.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index fa8236e64f..76c647d37f 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1830,11 +1830,15 @@ def _reset_plugins(self): def _collect_creator_items(self): # TODO add crashed initialization of create plugins to report output = {} + task_type = None + current_task_entity = get_current_task_entity() + if current_task_entity: + task_type = current_task_entity["taskType"] allowed_creator_identifiers = self._get_allowed_creator_identifiers( self.project_name, self._create_context.host_name, self.current_task_name, - get_current_task_entity()["taskType"], + task_type, self.log ) for identifier, creator in self._create_context.creators.items(): @@ -1867,10 +1871,7 @@ def _get_allowed_creator_identifiers( If no profile provided for current context, it shows all creators """ - allowed_creator_identifiers = [] - if host_name == "traypublisher": - # no real context known - return allowed_creator_identifiers + allowed_creator_identifiers = None proj_settings = get_project_settings(project_name) filter_creator_profiles = ( proj_settings From 3c287e1d64151f76487a504e40eb4afb21b7f0a0 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 14:13:49 +0200 Subject: [PATCH 10/31] AY-5539 - added project settings to CreatorContext --- client/ayon_core/pipeline/create/context.py | 18 ++++++++++++++++++ client/ayon_core/tools/publisher/control.py | 18 +++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 45846553a4..f29f2a12a0 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -1401,6 +1401,7 @@ def __init__( self._current_folder_path = None self._current_task_name = None self._current_workfile_path = None + self._current_project_settings = None self._current_project_anatomy = None @@ -1571,6 +1572,17 @@ def get_current_task_name(self): return self._current_task_name + def get_current_task_entity(self): + """Task name which was used as current context on context reset. + + Returns: + Union[str, None]: Task name. + """ + task_name = self.get_current_task_name() + if self._current_task_entity is None and task_name: + self._current_task_entity = get_current_task_entity() + return self._current_task_entity + def get_current_workfile_path(self): """Workfile path which was opened on context reset. @@ -1592,6 +1604,12 @@ def get_current_project_anatomy(self): self._current_project_name) return self._current_project_anatomy + def get_current_project_settings(self): + if self._current_project_settings is None: + self._current_project_settings = get_project_settings( + self.get_current_project_name()) + return self._current_project_settings + @property def context_has_changed(self): """Host context has changed. diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 76c647d37f..9b12b3c318 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -39,7 +39,6 @@ ) from ayon_core.pipeline.publish import get_publish_instance_label from ayon_core.tools.common_models import HierarchyModel -from ayon_core.settings import get_project_settings from ayon_core.lib.profiles_filtering import filter_profiles from ayon_core.pipeline.context_tools import get_current_task_entity @@ -1665,6 +1664,16 @@ def current_task_name(self): return self._create_context.get_current_task_name() + @property + def current_project_settings(self): + """Current project settings. + + Returns: + dict + """ + + return self._create_context.get_current_project_settings() + @property def host_context_has_changed(self): return self._create_context.context_has_changed @@ -1835,7 +1844,7 @@ def _collect_creator_items(self): if current_task_entity: task_type = current_task_entity["taskType"] allowed_creator_identifiers = self._get_allowed_creator_identifiers( - self.project_name, + self.current_project_settings, self._create_context.host_name, self.current_task_name, task_type, @@ -1861,7 +1870,7 @@ def _collect_creator_items(self): def _get_allowed_creator_identifiers( self, - project_name, + project_settings, host_name, task_name, task_type, @@ -1872,9 +1881,8 @@ def _get_allowed_creator_identifiers( If no profile provided for current context, it shows all creators """ allowed_creator_identifiers = None - proj_settings = get_project_settings(project_name) filter_creator_profiles = ( - proj_settings + project_settings ["core"] ["tools"] ["creator"] From cafb4c9ad099830a81f1018299036f24b49b45f5 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 16:28:18 +0200 Subject: [PATCH 11/31] Use host_names in Settings Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- server/settings/tools.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/settings/tools.py b/server/settings/tools.py index 37b0ddfd59..f1ee44168f 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -39,7 +39,9 @@ class FilterCreatorProfile(BaseSettingsModel): """Provide list of allowed Creator identifiers for context""" _layout = "expanded" - hosts: list[str] = SettingsField(default_factory=list, title="Hosts") + host_names: list[str] = SettingsField( + default_factory=list, title="Host names" + ) task_types: list[str] = SettingsField( default_factory=list, title="Task types", From e899dd05f36173435348f520d6d8229d8f71b937 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Wed, 29 May 2024 16:29:14 +0200 Subject: [PATCH 12/31] AY-5539 - changed value from Settings --- client/ayon_core/tools/publisher/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 9b12b3c318..08229ae7f4 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1891,7 +1891,7 @@ def _get_allowed_creator_identifiers( filtering_criteria = { "task_names": task_name, "task_types": task_type, - "hosts": host_name + "host_names": host_name } profile = filter_profiles( filter_creator_profiles, From 63a2e8f81e311eba37eb14a2d1741dcc28f4f3ca Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 30 May 2024 11:36:07 +0200 Subject: [PATCH 13/31] AY-5539 - removed get_current_task_entity Wasn't implemented properly, cannot import from context_tools because of circular import. --- client/ayon_core/pipeline/create/context.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index f29f2a12a0..f9ed61bc5b 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -1572,17 +1572,6 @@ def get_current_task_name(self): return self._current_task_name - def get_current_task_entity(self): - """Task name which was used as current context on context reset. - - Returns: - Union[str, None]: Task name. - """ - task_name = self.get_current_task_name() - if self._current_task_entity is None and task_name: - self._current_task_entity = get_current_task_entity() - return self._current_task_entity - def get_current_workfile_path(self): """Workfile path which was opened on context reset. From 4d812df9ad13356204368aa0feea5b66371ac393 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 30 May 2024 11:38:07 +0200 Subject: [PATCH 14/31] AY-5539 - reset project_setting when necessary --- client/ayon_core/pipeline/create/context.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index f9ed61bc5b..cca40362d6 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -1726,6 +1726,7 @@ def reset_current_context(self): self._current_workfile_path = workfile_path self._current_project_anatomy = None + self._current_project_settings = None def reset_plugins(self, discover_publish_plugins=True): """Reload plugins. From 7b6f8d24affd645854a94bcf248e326122bacaa0 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 30 May 2024 11:39:39 +0200 Subject: [PATCH 15/31] AY-5539 - use internal method for settings --- client/ayon_core/pipeline/create/context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index cca40362d6..35b78689f5 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -1780,7 +1780,7 @@ def _reset_publish_plugins(self, discover_publish_plugins): def _reset_creator_plugins(self): # Prepare settings - project_settings = get_project_settings(self.project_name) + project_settings = self.get_current_project_settings() # Discover and prepare creators creators = {} From 739d459e74b3e5e7390fe2eb38f7b4fce4bf832d Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 May 2024 12:29:56 +0200 Subject: [PATCH 16/31] CreateContext has methods to get folder & task entity and task type --- client/ayon_core/pipeline/create/context.py | 67 +++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/client/ayon_core/pipeline/create/context.py b/client/ayon_core/pipeline/create/context.py index 35b78689f5..0d8722dab1 100644 --- a/client/ayon_core/pipeline/create/context.py +++ b/client/ayon_core/pipeline/create/context.py @@ -37,6 +37,7 @@ # Changes of instances and context are send as tuple of 2 information UpdateData = collections.namedtuple("UpdateData", ["instance", "changes"]) +_NOT_SET = object() class UnavailableSharedData(Exception): @@ -1403,6 +1404,10 @@ def __init__( self._current_workfile_path = None self._current_project_settings = None + self._current_folder_entity = _NOT_SET + self._current_task_entity = _NOT_SET + self._current_task_type = _NOT_SET + self._current_project_anatomy = None self._host_is_valid = host_is_valid @@ -1572,6 +1577,64 @@ def get_current_task_name(self): return self._current_task_name + def get_current_task_type(self): + """Task type which was used as current context on context reset. + + Returns: + Union[str, None]: Task type. + + """ + if self._current_task_type is _NOT_SET: + task_type = None + task_entity = self.get_current_task_entity() + if task_entity: + task_type = task_entity["taskType"] + self._current_task_type = task_type + return self._current_task_type + + def get_current_folder_entity(self): + """Folder entity for current context folder. + + Returns: + Union[dict[str, Any], None]: Folder entity. + + """ + if self._current_folder_entity is not _NOT_SET: + return copy.deepcopy(self._current_folder_entity) + folder_entity = None + folder_path = self.get_current_folder_path() + if folder_path: + project_name = self.get_current_project_name() + folder_entity = ayon_api.get_folder_by_path( + project_name, folder_path + ) + self._current_folder_entity = folder_entity + return copy.deepcopy(self._current_folder_entity) + + def get_current_task_entity(self): + """Task entity for current context task. + + Returns: + Union[dict[str, Any], None]: Task entity. + + """ + if self._current_task_entity is not _NOT_SET: + return copy.deepcopy(self._current_task_entity) + task_entity = None + task_name = self.get_current_task_name() + if task_name: + folder_entity = self.get_current_folder_entity() + if folder_entity: + project_name = self.get_current_project_name() + task_entity = ayon_api.get_task_by_name( + project_name, + folder_id=folder_entity["id"], + task_name=task_name + ) + self._current_task_entity = task_entity + return copy.deepcopy(self._current_task_entity) + + def get_current_workfile_path(self): """Workfile path which was opened on context reset. @@ -1725,6 +1788,10 @@ def reset_current_context(self): self._current_task_name = task_name self._current_workfile_path = workfile_path + self._current_folder_entity = _NOT_SET + self._current_task_entity = _NOT_SET + self._current_task_type = _NOT_SET + self._current_project_anatomy = None self._current_project_settings = None From ec0327f44f1de63f00d539148c2b0849fbb9d7e7 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 May 2024 12:30:59 +0200 Subject: [PATCH 17/31] use new method in publish controller --- client/ayon_core/tools/publisher/control.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 08229ae7f4..acbd7683ad 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1839,10 +1839,7 @@ def _reset_plugins(self): def _collect_creator_items(self): # TODO add crashed initialization of create plugins to report output = {} - task_type = None - current_task_entity = get_current_task_entity() - if current_task_entity: - task_type = current_task_entity["taskType"] + task_type = self._create_context.get_current_task_type() allowed_creator_identifiers = self._get_allowed_creator_identifiers( self.current_project_settings, self._create_context.host_name, From 6e2cdf36a0b887840f7f30ffb502c6d45aaa0d33 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 May 2024 12:33:46 +0200 Subject: [PATCH 18/31] '_get_allowed_creator_identifiers' does not expect any arguments --- client/ayon_core/tools/publisher/control.py | 47 ++++++++------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index acbd7683ad..61bd74de5a 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1664,16 +1664,6 @@ def current_task_name(self): return self._create_context.get_current_task_name() - @property - def current_project_settings(self): - """Current project settings. - - Returns: - dict - """ - - return self._create_context.get_current_project_settings() - @property def host_context_has_changed(self): return self._create_context.context_has_changed @@ -1698,6 +1688,15 @@ def _publish_plugins(self): """Publish plugins.""" return self._create_context.publish_plugins + def _get_current_project_settings(self): + """Current project settings. + + Returns: + dict + """ + + return self._create_context.get_current_project_settings() + # Hierarchy model def get_folder_items(self, project_name, sender=None): return self._hierarchy_model.get_folder_items(project_name, sender) @@ -1839,14 +1838,7 @@ def _reset_plugins(self): def _collect_creator_items(self): # TODO add crashed initialization of create plugins to report output = {} - task_type = self._create_context.get_current_task_type() - allowed_creator_identifiers = self._get_allowed_creator_identifiers( - self.current_project_settings, - self._create_context.host_name, - self.current_task_name, - task_type, - self.log - ) + allowed_creator_identifiers = self._get_allowed_creator_identifiers() for identifier, creator in self._create_context.creators.items(): try: if ( @@ -1865,18 +1857,15 @@ def _collect_creator_items(self): return output - def _get_allowed_creator_identifiers( - self, - project_settings, - host_name, - task_name, - task_type, - log=None - ): + def _get_allowed_creator_identifiers(self): """Provide configured creator identifier in this context If no profile provided for current context, it shows all creators """ + + task_type = self._create_context.get_current_task_type() + project_settings = self._get_current_project_settings() + allowed_creator_identifiers = None filter_creator_profiles = ( project_settings @@ -1886,14 +1875,14 @@ def _get_allowed_creator_identifiers( ["filter_creator_profiles"] ) filtering_criteria = { - "task_names": task_name, + "task_names": self.current_task_name, "task_types": task_type, - "host_names": host_name + "host_names": self._create_context.host_name } profile = filter_profiles( filter_creator_profiles, filtering_criteria, - logger=log + logger=self.log ) if profile: From 31c2d7ef3b0c901f1592d6b5157b082b213570c2 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 30 May 2024 13:02:21 +0200 Subject: [PATCH 19/31] removed unused import --- client/ayon_core/tools/publisher/control.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 61bd74de5a..0a933ffbfb 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -40,7 +40,6 @@ from ayon_core.pipeline.publish import get_publish_instance_label from ayon_core.tools.common_models import HierarchyModel from ayon_core.lib.profiles_filtering import filter_profiles -from ayon_core.pipeline.context_tools import get_current_task_entity # Define constant for plugin orders offset PLUGIN_ORDER_OFFSET = 0.5 From 96c11e6a332a5d3d5a2476c8428136fe7259ed19 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 31 May 2024 12:47:00 +0200 Subject: [PATCH 20/31] AY-5539 - used labels instead of identifiers Identifiers are bit hard to get to fill them into Settings, labels are visible in Publisher and can by Copy&Pasted. --- client/ayon_core/tools/publisher/control.py | 20 ++++++++++---------- server/settings/tools.py | 10 +++++++--- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 61bd74de5a..1ded279aa2 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1838,14 +1838,14 @@ def _reset_plugins(self): def _collect_creator_items(self): # TODO add crashed initialization of create plugins to report output = {} - allowed_creator_identifiers = self._get_allowed_creator_identifiers() + allowed_creator_labels = self._get_allowed_creator_labels() for identifier, creator in self._create_context.creators.items(): try: if ( - allowed_creator_identifiers is not None - and identifier not in allowed_creator_identifiers + allowed_creator_labels is not None + and creator.label not in allowed_creator_labels ): - self.log.debug(f"{identifier} not allowed for context") + self.log.debug(f"{creator.label} not allowed for context") continue output[identifier] = CreatorItem.from_creator(creator) except Exception: @@ -1857,16 +1857,16 @@ def _collect_creator_items(self): return output - def _get_allowed_creator_identifiers(self): - """Provide configured creator identifier in this context + def _get_allowed_creator_labels(self): + """Provide configured creator label in this context - If no profile provided for current context, it shows all creators + If no profile matches current context, it shows all creators """ task_type = self._create_context.get_current_task_type() project_settings = self._get_current_project_settings() - allowed_creator_identifiers = None + allowed_creator_labels = None filter_creator_profiles = ( project_settings ["core"] @@ -1886,8 +1886,8 @@ def _get_allowed_creator_identifiers(self): ) if profile: - allowed_creator_identifiers = profile["creator_identifiers"] - return allowed_creator_identifiers + allowed_creator_labels = profile["creator_labels"] + return allowed_creator_labels def _reset_instances(self): """Reset create instances.""" diff --git a/server/settings/tools.py b/server/settings/tools.py index f1ee44168f..ed0c723bac 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -50,9 +50,11 @@ class FilterCreatorProfile(BaseSettingsModel): task_names: list[str] = SettingsField( default_factory=list, title="Task names") - creator_identifiers: list[str] = SettingsField( + creator_labels: list[str] = SettingsField( default_factory=list, - title="Allowed Creator Identifiers") + title="Allowed Creator Labels", + description="Copy creator label from Publisher, regex supported." + ) class CreatorToolModel(BaseSettingsModel): @@ -70,7 +72,9 @@ class CreatorToolModel(BaseSettingsModel): filter_creator_profiles: list[FilterCreatorProfile] = SettingsField( default_factory=list, - title="Filter creator profiles" + title="Filter creator profiles", + description="White list of creator labels that will be only shown if " + "profile matches context." ) @validator("product_types_smart_select") From 5a314354b7b23473f97c609c897f423649a5ecb1 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 31 May 2024 13:00:17 +0200 Subject: [PATCH 21/31] AY-5539 - support regex in creator label --- client/ayon_core/tools/publisher/control.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 1ded279aa2..a15ab09256 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -8,6 +8,7 @@ import shutil import inspect from abc import ABCMeta, abstractmethod +import re import six import arrow @@ -1843,7 +1844,8 @@ def _collect_creator_items(self): try: if ( allowed_creator_labels is not None - and creator.label not in allowed_creator_labels + and not self._label_matches_allowed( + creator.label, allowed_creator_labels) ): self.log.debug(f"{creator.label} not allowed for context") continue @@ -1889,6 +1891,13 @@ def _get_allowed_creator_labels(self): allowed_creator_labels = profile["creator_labels"] return allowed_creator_labels + def _label_matches_allowed(self, label, allowed_labels): + """Implement regex support for allowed labels.""" + for allowed in allowed_labels: + if re.match(allowed, label): + return True + return False + def _reset_instances(self): """Reset create instances.""" if self._resetting_instances: From 2794190160cfb370c160c65e5158bb5607ab5f3b Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 31 May 2024 13:01:44 +0200 Subject: [PATCH 22/31] AY-5539 - added logging on profile match --- client/ayon_core/tools/publisher/control.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index a15ab09256..abf116d337 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1889,6 +1889,7 @@ def _get_allowed_creator_labels(self): if profile: allowed_creator_labels = profile["creator_labels"] + self.log.debug(f"Only allowed `{allowed_creator_labels}` creators") return allowed_creator_labels def _label_matches_allowed(self, label, allowed_labels): From d2d05f64f75efd33501b000925c27d90214a17f7 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 31 May 2024 13:31:47 +0200 Subject: [PATCH 23/31] Updated description Co-authored-by: Roy Nieterau --- server/settings/tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/settings/tools.py b/server/settings/tools.py index ed0c723bac..6c02a928bf 100644 --- a/server/settings/tools.py +++ b/server/settings/tools.py @@ -73,7 +73,7 @@ class CreatorToolModel(BaseSettingsModel): filter_creator_profiles: list[FilterCreatorProfile] = SettingsField( default_factory=list, title="Filter creator profiles", - description="White list of creator labels that will be only shown if " + description="Allowed list of creator labels that will be only shown if " "profile matches context." ) From 0fe6526ae9d0b207c43ad85d867b354ea79a2ac1 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 31 May 2024 13:34:41 +0200 Subject: [PATCH 24/31] AY-5539 - possible speedup of resolution --- client/ayon_core/tools/publisher/control.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index b38df857c0..e73c68a295 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1893,9 +1893,9 @@ def _get_allowed_creator_labels(self): def _label_matches_allowed(self, label, allowed_labels): """Implement regex support for allowed labels.""" - for allowed in allowed_labels: - if re.match(allowed, label): - return True + allowed_patterns = re.compile("|".join(allowed_labels)) + if allowed_patterns.match(label): + return True return False def _reset_instances(self): From 0fa90417369919248500d6b83ccbfca4f125e602 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 3 Jun 2024 11:42:29 +0200 Subject: [PATCH 25/31] AY-5539 - update resolution logic --- client/ayon_core/tools/publisher/control.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index e73c68a295..9578b07b15 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1841,11 +1841,8 @@ def _collect_creator_items(self): allowed_creator_labels = self._get_allowed_creator_labels() for identifier, creator in self._create_context.creators.items(): try: - if ( - allowed_creator_labels is not None - and not self._label_matches_allowed( - creator.label, allowed_creator_labels) - ): + if (not self._label_matches_allowed( + creator.label, allowed_creator_labels)): self.log.debug(f"{creator.label} not allowed for context") continue output[identifier] = CreatorItem.from_creator(creator) @@ -1893,9 +1890,10 @@ def _get_allowed_creator_labels(self): def _label_matches_allowed(self, label, allowed_labels): """Implement regex support for allowed labels.""" - allowed_patterns = re.compile("|".join(allowed_labels)) - if allowed_patterns.match(label): - return True + if allowed_labels: + allowed_patterns = re.compile("|".join(allowed_labels)) + if allowed_patterns.match(label): + return True return False def _reset_instances(self): From c7f0e977f79d6b35ba9f782d21a4da58145901ba Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 3 Jun 2024 11:45:13 +0200 Subject: [PATCH 26/31] AY-5539 - refactor variable position --- client/ayon_core/tools/publisher/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 9578b07b15..c9680b1d9e 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1864,7 +1864,6 @@ def _get_allowed_creator_labels(self): task_type = self._create_context.get_current_task_type() project_settings = self._get_current_project_settings() - allowed_creator_labels = None filter_creator_profiles = ( project_settings ["core"] @@ -1883,6 +1882,7 @@ def _get_allowed_creator_labels(self): logger=self.log ) + allowed_creator_labels = None if profile: allowed_creator_labels = profile["creator_labels"] self.log.debug(f"Only allowed `{allowed_creator_labels}` creators") From 4e07b756af65cdb08c58271976bf95b7216ad306 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 3 Jun 2024 12:06:29 +0200 Subject: [PATCH 27/31] AY-5539 - fix wrong logic --- client/ayon_core/tools/publisher/control.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index c9680b1d9e..72a89d2a3a 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1841,7 +1841,7 @@ def _collect_creator_items(self): allowed_creator_labels = self._get_allowed_creator_labels() for identifier, creator in self._create_context.creators.items(): try: - if (not self._label_matches_allowed( + if (not self._is_label_allowed( creator.label, allowed_creator_labels)): self.log.debug(f"{creator.label} not allowed for context") continue @@ -1888,13 +1888,12 @@ def _get_allowed_creator_labels(self): self.log.debug(f"Only allowed `{allowed_creator_labels}` creators") return allowed_creator_labels - def _label_matches_allowed(self, label, allowed_labels): + def _is_label_allowed(self, label, allowed_labels): """Implement regex support for allowed labels.""" - if allowed_labels: - allowed_patterns = re.compile("|".join(allowed_labels)) - if allowed_patterns.match(label): - return True - return False + if not allowed_labels: + return True + allowed_patterns = re.compile("|".join(allowed_labels)) + return bool(allowed_patterns.match(label)) def _reset_instances(self): """Reset create instances.""" From 577da3fb7fcbc2a217d487708b093d81f6c5dee9 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 3 Jun 2024 15:57:30 +0200 Subject: [PATCH 28/31] AY-5539 - protect from empty field in Settings --- client/ayon_core/tools/publisher/control.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 72a89d2a3a..66487343d1 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1884,7 +1884,11 @@ def _get_allowed_creator_labels(self): allowed_creator_labels = None if profile: - allowed_creator_labels = profile["creator_labels"] + allowed_creator_labels = { + label + for label in profile["creator_labels"] + if label + } self.log.debug(f"Only allowed `{allowed_creator_labels}` creators") return allowed_creator_labels From dd02631786628729fec3fcb696696d1761d513bb Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 3 Jun 2024 17:46:01 +0200 Subject: [PATCH 29/31] AY-5539 - do only single re compile re.compile might be expensive, do it outside of loop --- client/ayon_core/tools/publisher/control.py | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 66487343d1..f2a440d701 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1856,9 +1856,13 @@ def _collect_creator_items(self): return output def _get_allowed_creator_labels(self): - """Provide configured creator label in this context + """Provide configured creator labels in this context - If no profile matches current context, it shows all creators + If no profile matches current context, it shows all creators. + Support usage of regular expressions for configured values. + Returns: + (str): None or regex compiled patterns into single one + ('Render|Image.*') """ task_type = self._create_context.get_current_task_type() @@ -1890,14 +1894,20 @@ def _get_allowed_creator_labels(self): if label } self.log.debug(f"Only allowed `{allowed_creator_labels}` creators") + allowed_creator_labels = ( + re.compile("|".join(allowed_creator_labels))) return allowed_creator_labels - def _is_label_allowed(self, label, allowed_labels): - """Implement regex support for allowed labels.""" - if not allowed_labels: + def _is_label_allowed(self, label, allowed_label_regexes): + """Implement regex support for allowed labels. + + Args: + label (str): Label of creator - shown in Publisher + allowed_label_regexes (str): compiled regular expression + """ + if not allowed_label_regexes: return True - allowed_patterns = re.compile("|".join(allowed_labels)) - return bool(allowed_patterns.match(label)) + return bool(allowed_label_regexes.match(label)) def _reset_instances(self): """Reset create instances.""" From cbc0516475a06bc930e725cef6a7147bc160dd7d Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 6 Jun 2024 11:44:54 +0200 Subject: [PATCH 30/31] AY-5539 - refactor argument name --- client/ayon_core/tools/publisher/control.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index f2a440d701..510885ddad 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1898,16 +1898,16 @@ def _get_allowed_creator_labels(self): re.compile("|".join(allowed_creator_labels))) return allowed_creator_labels - def _is_label_allowed(self, label, allowed_label_regexes): + def _is_label_allowed(self, label, allowed_labels_regex): """Implement regex support for allowed labels. Args: label (str): Label of creator - shown in Publisher - allowed_label_regexes (str): compiled regular expression + allowed_labels_regex (re.Pattern): compiled regular expression """ - if not allowed_label_regexes: + if not allowed_labels_regex: return True - return bool(allowed_label_regexes.match(label)) + return bool(allowed_labels_regex.match(label)) def _reset_instances(self): """Reset create instances.""" From 909d6e74e782d755d1d0d9685296aa9c0d852d82 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Thu, 6 Jun 2024 11:49:04 +0200 Subject: [PATCH 31/31] AY-5539 - refactor name of method --- client/ayon_core/tools/publisher/control.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/client/ayon_core/tools/publisher/control.py b/client/ayon_core/tools/publisher/control.py index 510885ddad..4e2cfd8783 100644 --- a/client/ayon_core/tools/publisher/control.py +++ b/client/ayon_core/tools/publisher/control.py @@ -1838,11 +1838,11 @@ def _reset_plugins(self): def _collect_creator_items(self): # TODO add crashed initialization of create plugins to report output = {} - allowed_creator_labels = self._get_allowed_creator_labels() + allowed_creator_pattern = self._get_allowed_creators_pattern() for identifier, creator in self._create_context.creators.items(): try: if (not self._is_label_allowed( - creator.label, allowed_creator_labels)): + creator.label, allowed_creator_pattern)): self.log.debug(f"{creator.label} not allowed for context") continue output[identifier] = CreatorItem.from_creator(creator) @@ -1855,14 +1855,14 @@ def _collect_creator_items(self): return output - def _get_allowed_creator_labels(self): - """Provide configured creator labels in this context + def _get_allowed_creators_pattern(self): + """Provide regex pattern for configured creator labels in this context If no profile matches current context, it shows all creators. Support usage of regular expressions for configured values. Returns: - (str): None or regex compiled patterns into single one - ('Render|Image.*') + (re.Pattern)[optional]: None or regex compiled patterns + into single one ('Render|Image.*') """ task_type = self._create_context.get_current_task_type() @@ -1886,7 +1886,7 @@ def _get_allowed_creator_labels(self): logger=self.log ) - allowed_creator_labels = None + allowed_creator_pattern = None if profile: allowed_creator_labels = { label @@ -1894,9 +1894,9 @@ def _get_allowed_creator_labels(self): if label } self.log.debug(f"Only allowed `{allowed_creator_labels}` creators") - allowed_creator_labels = ( + allowed_creator_pattern = ( re.compile("|".join(allowed_creator_labels))) - return allowed_creator_labels + return allowed_creator_pattern def _is_label_allowed(self, label, allowed_labels_regex): """Implement regex support for allowed labels.