From 0ec066af7ed1a34f40d162a6e40ad9f6aa0f9d88 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 18:12:47 +0200 Subject: [PATCH 01/23] defined constants in ftrack lib --- openpype/modules/ftrack/lib/__init__.py | 13 +++++++++++++ openpype/modules/ftrack/lib/constants.py | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 openpype/modules/ftrack/lib/constants.py diff --git a/openpype/modules/ftrack/lib/__init__.py b/openpype/modules/ftrack/lib/__init__.py index 82b6875590..87dadf6480 100644 --- a/openpype/modules/ftrack/lib/__init__.py +++ b/openpype/modules/ftrack/lib/__init__.py @@ -1,3 +1,10 @@ +from .constants import ( + CUST_ATTR_ID_KEY, + CUST_ATTR_AUTO_SYNC, + CUST_ATTR_GROUP, + CUST_ATTR_TOOLS, + CUST_ATTR_APPLICATIONS +) from . settings import ( get_ftrack_url_from_settings, get_ftrack_event_mongo_info @@ -10,6 +17,12 @@ from .ftrack_action_handler import BaseAction, ServerAction, statics_icon __all__ = ( + "CUST_ATTR_ID_KEY", + "CUST_ATTR_AUTO_SYNC", + "CUST_ATTR_GROUP", + "CUST_ATTR_TOOLS", + "CUST_ATTR_APPLICATIONS", + "get_ftrack_url_from_settings", "get_ftrack_event_mongo_info", diff --git a/openpype/modules/ftrack/lib/constants.py b/openpype/modules/ftrack/lib/constants.py new file mode 100644 index 0000000000..73d5112e6d --- /dev/null +++ b/openpype/modules/ftrack/lib/constants.py @@ -0,0 +1,12 @@ +# Group name of custom attributes +CUST_ATTR_GROUP = "openpype" + +# name of Custom attribute that stores mongo_id from avalon db +CUST_ATTR_ID_KEY = "avalon_mongo_id" +# Auto sync of project +CUST_ATTR_AUTO_SYNC = "avalon_auto_sync" + +# Applications custom attribute name +CUST_ATTR_APPLICATIONS = "applications" +# Environment tools custom attribute +CUST_ATTR_TOOLS = "tools_env" From 5fbc62678b168ff1134ccb6e75803ce162e9b428 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 18:13:13 +0200 Subject: [PATCH 02/23] fixed and replaced import of constants --- .../action_create_cust_attrs.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py b/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py index 63025d35b3..8d585dee20 100644 --- a/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py +++ b/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py @@ -2,9 +2,16 @@ import collections import json import arrow import ftrack_api -from openpype.modules.ftrack.lib import BaseAction, statics_icon +from openpype.modules.ftrack.lib import ( + BaseAction, + statics_icon, + CUST_ATTR_ID_KEY, + CUST_ATTR_GROUP, + CUST_ATTR_TOOLS, + CUST_ATTR_APPLICATIONS +) from openpype.modules.ftrack.lib.avalon_sync import ( - CUST_ATTR_ID_KEY, CUST_ATTR_GROUP, default_custom_attributes_definition + default_custom_attributes_definition ) from openpype.api import get_system_settings from openpype.lib import ApplicationManager @@ -387,7 +394,7 @@ class CustomAttributes(BaseAction): applications_custom_attr_data = { "label": "Applications", - "key": "applications", + "key": CUST_ATTR_APPLICATIONS, "type": "enumerator", "entity_type": "show", "group": CUST_ATTR_GROUP, @@ -411,7 +418,7 @@ class CustomAttributes(BaseAction): tools_custom_attr_data = { "label": "Tools", - "key": "tools_env", + "key": CUST_ATTR_TOOLS, "type": "enumerator", "is_hierarchical": True, "group": CUST_ATTR_GROUP, From 3f63fc7a9b4eb6105f33dd509dd8a4ee155c3f40 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 18:13:27 +0200 Subject: [PATCH 03/23] avalon_sync is using constants defined in constants.py --- openpype/modules/ftrack/lib/avalon_sync.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/openpype/modules/ftrack/lib/avalon_sync.py b/openpype/modules/ftrack/lib/avalon_sync.py index 79e1366a0d..5f44181e5f 100644 --- a/openpype/modules/ftrack/lib/avalon_sync.py +++ b/openpype/modules/ftrack/lib/avalon_sync.py @@ -26,6 +26,12 @@ from pymongo import UpdateOne import ftrack_api from openpype.lib import ApplicationManager +from .constants import ( + CUST_ATTR_ID_KEY, + CUST_ATTR_AUTO_SYNC, + CUST_ATTR_GROUP +) + log = Logger.get_logger(__name__) @@ -36,14 +42,6 @@ EntitySchemas = { "config": "openpype:config-2.0" } -# Group name of custom attributes -CUST_ATTR_GROUP = "openpype" - -# name of Custom attribute that stores mongo_id from avalon db -CUST_ATTR_ID_KEY = "avalon_mongo_id" -CUST_ATTR_AUTO_SYNC = "avalon_auto_sync" - - def default_custom_attributes_definition(): json_file_path = os.path.join( os.path.dirname(os.path.abspath(__file__)), From 10b362937b1ce0887204882e5b9334e74dc7987b Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 18:27:42 +0200 Subject: [PATCH 04/23] application manager can be initialized to use different settings --- openpype/lib/applications.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/openpype/lib/applications.py b/openpype/lib/applications.py index 51c646d494..dc83037378 100644 --- a/openpype/lib/applications.py +++ b/openpype/lib/applications.py @@ -261,14 +261,32 @@ class Application: class ApplicationManager: - def __init__(self): - self.log = PypeLogger().get_logger(self.__class__.__name__) + """Load applications and tools and store them by their full name. + + Args: + system_settings (dict): Preloaded system settings. When passed manager + will always use these values. Gives ability to create manager + using different settings. + """ + def __init__(self, system_settings=None): + self.log = PypeLogger.get_logger(self.__class__.__name__) self.app_groups = {} self.applications = {} self.tool_groups = {} self.tools = {} + self._system_settings = system_settings + + self.refresh() + + def set_system_settings(self, system_settings): + """Ability to change init system settings. + + This will trigger refresh of manager. + """ + self._system_settings = system_settings + self.refresh() def refresh(self): @@ -278,9 +296,12 @@ class ApplicationManager: self.tool_groups.clear() self.tools.clear() - settings = get_system_settings( - clear_metadata=False, exclude_locals=False - ) + if self._system_settings is not None: + settings = copy.deepcopy(self._system_settings) + else: + settings = get_system_settings( + clear_metadata=False, exclude_locals=False + ) app_defs = settings["applications"] for group_name, variant_defs in app_defs.items(): From d746c4009f487ec34ae75c34a7ae9355b77af903 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 18:49:29 +0200 Subject: [PATCH 05/23] added custom_attributes.py to ftrack lib --- openpype/modules/ftrack/lib/__init__.py | 10 +++++ .../modules/ftrack/lib/custom_attributes.py | 38 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 openpype/modules/ftrack/lib/custom_attributes.py diff --git a/openpype/modules/ftrack/lib/__init__.py b/openpype/modules/ftrack/lib/__init__.py index 87dadf6480..bc0c989c02 100644 --- a/openpype/modules/ftrack/lib/__init__.py +++ b/openpype/modules/ftrack/lib/__init__.py @@ -9,6 +9,12 @@ from . settings import ( get_ftrack_url_from_settings, get_ftrack_event_mongo_info ) +from .custm_attributes import ( + default_custom_attributes_definition, + app_definitions_from_app_manager, + tool_definitions_from_app_manager +) + from . import avalon_sync from . import credentials from .ftrack_base_handler import BaseHandler @@ -26,6 +32,10 @@ __all__ = ( "get_ftrack_url_from_settings", "get_ftrack_event_mongo_info", + "default_custom_attributes_definition", + "app_definitions_from_app_manager", + "tool_definitions_from_app_manager", + "avalon_sync", "credentials", diff --git a/openpype/modules/ftrack/lib/custom_attributes.py b/openpype/modules/ftrack/lib/custom_attributes.py new file mode 100644 index 0000000000..18efd7bcae --- /dev/null +++ b/openpype/modules/ftrack/lib/custom_attributes.py @@ -0,0 +1,38 @@ +import os +import json + + +def default_custom_attributes_definition(): + json_file_path = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "custom_attributes.json" + ) + with open(json_file_path, "r") as json_stream: + data = json.load(json_stream) + return data + + +def app_definitions_from_app_manager(app_manager): + app_definitions = [] + for app_name, app in app_manager.applications.items(): + if app.enabled and app.is_host: + app_definitions.append({ + app_name: app.full_label + }) + + if not app_definitions: + app_definitions.append({"empty": "< Empty >"}) + return app_definitions + + +def tool_definitions_from_app_manager(app_manager): + tools_data = [] + for tool_name, tool in app_manager.tools.items(): + tools_data.append({ + tool_name: tool.label + }) + + # Make sure there is at least one item + if not tools_data: + tools_data.append({"empty": "< Empty >"}) + return tools_data From d9ef2b59abdbeb7147cf21db47592147cb7f0d0f Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 18:49:51 +0200 Subject: [PATCH 06/23] create update custom attributes is using functions from lib --- .../action_create_cust_attrs.py | 35 +++++-------------- openpype/modules/ftrack/lib/avalon_sync.py | 9 ----- 2 files changed, 9 insertions(+), 35 deletions(-) diff --git a/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py b/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py index 8d585dee20..63605eda5e 100644 --- a/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py +++ b/openpype/modules/ftrack/event_handlers_user/action_create_cust_attrs.py @@ -5,14 +5,17 @@ import ftrack_api from openpype.modules.ftrack.lib import ( BaseAction, statics_icon, + CUST_ATTR_ID_KEY, CUST_ATTR_GROUP, CUST_ATTR_TOOLS, - CUST_ATTR_APPLICATIONS -) -from openpype.modules.ftrack.lib.avalon_sync import ( - default_custom_attributes_definition + CUST_ATTR_APPLICATIONS, + + default_custom_attributes_definition, + app_definitions_from_app_manager, + tool_definitions_from_app_manager ) + from openpype.api import get_system_settings from openpype.lib import ApplicationManager @@ -377,20 +380,8 @@ class CustomAttributes(BaseAction): exc_info=True ) - def app_defs_from_app_manager(self): - app_definitions = [] - for app_name, app in self.app_manager.applications.items(): - if app.enabled and app.is_host: - app_definitions.append({ - app_name: app.full_label - }) - - if not app_definitions: - app_definitions.append({"empty": "< Empty >"}) - return app_definitions - def applications_attribute(self, event): - apps_data = self.app_defs_from_app_manager() + apps_data = app_definitions_from_app_manager(self.app_manager) applications_custom_attr_data = { "label": "Applications", @@ -406,15 +397,7 @@ class CustomAttributes(BaseAction): self.process_attr_data(applications_custom_attr_data, event) def tools_attribute(self, event): - tools_data = [] - for tool_name, tool in self.app_manager.tools.items(): - tools_data.append({ - tool_name: tool.label - }) - - # Make sure there is at least one item - if not tools_data: - tools_data.append({"empty": "< Empty >"}) + tools_data = tool_definitions_from_app_manager(self.app_manager) tools_custom_attr_data = { "label": "Tools", diff --git a/openpype/modules/ftrack/lib/avalon_sync.py b/openpype/modules/ftrack/lib/avalon_sync.py index 5f44181e5f..6e83be8b64 100644 --- a/openpype/modules/ftrack/lib/avalon_sync.py +++ b/openpype/modules/ftrack/lib/avalon_sync.py @@ -42,15 +42,6 @@ EntitySchemas = { "config": "openpype:config-2.0" } -def default_custom_attributes_definition(): - json_file_path = os.path.join( - os.path.dirname(os.path.abspath(__file__)), - "custom_attributes.json" - ) - with open(json_file_path, "r") as json_stream: - data = json.load(json_stream) - return data - def check_regex(name, entity_type, in_schema=None, schema_patterns=None): schema_name = "asset-3.0" From 02238eef7cbbdcce38d6fe0ccc64f44991907f40 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 19:07:53 +0200 Subject: [PATCH 07/23] added `get_openpype_attr` to custom_attributes --- openpype/modules/ftrack/lib/__init__.py | 6 ++-- .../modules/ftrack/lib/custom_attributes.py | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/openpype/modules/ftrack/lib/__init__.py b/openpype/modules/ftrack/lib/__init__.py index bc0c989c02..ce6d5284b6 100644 --- a/openpype/modules/ftrack/lib/__init__.py +++ b/openpype/modules/ftrack/lib/__init__.py @@ -9,10 +9,11 @@ from . settings import ( get_ftrack_url_from_settings, get_ftrack_event_mongo_info ) -from .custm_attributes import ( +from .custom_attributes import ( default_custom_attributes_definition, app_definitions_from_app_manager, - tool_definitions_from_app_manager + tool_definitions_from_app_manager, + get_openpype_attr ) from . import avalon_sync @@ -35,6 +36,7 @@ __all__ = ( "default_custom_attributes_definition", "app_definitions_from_app_manager", "tool_definitions_from_app_manager", + "get_openpype_attr", "avalon_sync", diff --git a/openpype/modules/ftrack/lib/custom_attributes.py b/openpype/modules/ftrack/lib/custom_attributes.py index 18efd7bcae..33eea32baa 100644 --- a/openpype/modules/ftrack/lib/custom_attributes.py +++ b/openpype/modules/ftrack/lib/custom_attributes.py @@ -1,6 +1,8 @@ import os import json +from .constants import CUST_ATTR_GROUP + def default_custom_attributes_definition(): json_file_path = os.path.join( @@ -36,3 +38,36 @@ def tool_definitions_from_app_manager(app_manager): if not tools_data: tools_data.append({"empty": "< Empty >"}) return tools_data + + +def get_openpype_attr(session, split_hierarchical=True, query_keys=None): + custom_attributes = [] + hier_custom_attributes = [] + if not query_keys: + query_keys = [ + "id", + "entity_type", + "object_type_id", + "is_hierarchical", + "default" + ] + # TODO remove deprecated "pype" group from query + cust_attrs_query = ( + "select {}" + " from CustomAttributeConfiguration" + # Kept `pype` for Backwards Compatiblity + " where group.name in (\"pype\", \"{}\")" + ).format(", ".join(query_keys), CUST_ATTR_GROUP) + all_avalon_attr = session.query(cust_attrs_query).all() + for cust_attr in all_avalon_attr: + if split_hierarchical and cust_attr["is_hierarchical"]: + hier_custom_attributes.append(cust_attr) + continue + + custom_attributes.append(cust_attr) + + if split_hierarchical: + # return tuple + return custom_attributes, hier_custom_attributes + + return custom_attributes From eb1b9556673b63d51ef324fb5a13e2caceb07b43 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 19:09:30 +0200 Subject: [PATCH 08/23] replaced usage of get_pype_attr with get_openpype_attr --- .../action_prepare_project.py | 8 ++-- .../event_sync_to_avalon.py | 9 +++-- .../action_clean_hierarchical_attributes.py | 9 +++-- .../action_prepare_project.py | 8 ++-- openpype/modules/ftrack/ftrack_module.py | 4 +- openpype/modules/ftrack/lib/avalon_sync.py | 38 ++----------------- 6 files changed, 24 insertions(+), 52 deletions(-) diff --git a/openpype/modules/ftrack/event_handlers_server/action_prepare_project.py b/openpype/modules/ftrack/event_handlers_server/action_prepare_project.py index 8248bf532e..12d687bbf2 100644 --- a/openpype/modules/ftrack/event_handlers_server/action_prepare_project.py +++ b/openpype/modules/ftrack/event_handlers_server/action_prepare_project.py @@ -2,9 +2,9 @@ import json from openpype.api import ProjectSettings -from openpype.modules.ftrack.lib import ServerAction -from openpype.modules.ftrack.lib.avalon_sync import ( - get_pype_attr, +from openpype.modules.ftrack.lib import ( + ServerAction, + get_openpype_attr, CUST_ATTR_AUTO_SYNC ) @@ -159,7 +159,7 @@ class PrepareProjectServer(ServerAction): for key, entity in project_anatom_settings["attributes"].items(): attribute_values_by_key[key] = entity.value - cust_attrs, hier_cust_attrs = get_pype_attr(self.session, True) + cust_attrs, hier_cust_attrs = get_openpype_attr(self.session, True) for attr in hier_cust_attrs: key = attr["key"] diff --git a/openpype/modules/ftrack/event_handlers_server/event_sync_to_avalon.py b/openpype/modules/ftrack/event_handlers_server/event_sync_to_avalon.py index 347b227dd3..3bb01798e4 100644 --- a/openpype/modules/ftrack/event_handlers_server/event_sync_to_avalon.py +++ b/openpype/modules/ftrack/event_handlers_server/event_sync_to_avalon.py @@ -18,12 +18,15 @@ from avalon import schema from avalon.api import AvalonMongoDB from openpype.modules.ftrack.lib import ( + get_openpype_attr, + CUST_ATTR_ID_KEY, + CUST_ATTR_AUTO_SYNC, + avalon_sync, + BaseEvent ) from openpype.modules.ftrack.lib.avalon_sync import ( - CUST_ATTR_ID_KEY, - CUST_ATTR_AUTO_SYNC, EntitySchemas ) @@ -125,7 +128,7 @@ class SyncToAvalonEvent(BaseEvent): @property def avalon_cust_attrs(self): if self._avalon_cust_attrs is None: - self._avalon_cust_attrs = avalon_sync.get_pype_attr( + self._avalon_cust_attrs = get_openpype_attr( self.process_session, query_keys=self.cust_attr_query_keys ) return self._avalon_cust_attrs diff --git a/openpype/modules/ftrack/event_handlers_user/action_clean_hierarchical_attributes.py b/openpype/modules/ftrack/event_handlers_user/action_clean_hierarchical_attributes.py index c326c56a7c..45cc9adf55 100644 --- a/openpype/modules/ftrack/event_handlers_user/action_clean_hierarchical_attributes.py +++ b/openpype/modules/ftrack/event_handlers_user/action_clean_hierarchical_attributes.py @@ -1,7 +1,10 @@ import collections import ftrack_api -from openpype.modules.ftrack.lib import BaseAction, statics_icon -from openpype.modules.ftrack.lib.avalon_sync import get_pype_attr +from openpype.modules.ftrack.lib import ( + BaseAction, + statics_icon, + get_openpype_attr +) class CleanHierarchicalAttrsAction(BaseAction): @@ -52,7 +55,7 @@ class CleanHierarchicalAttrsAction(BaseAction): ) entity_ids_joined = ", ".join(all_entities_ids) - attrs, hier_attrs = get_pype_attr(session) + attrs, hier_attrs = get_openpype_attr(session) for attr in hier_attrs: configuration_key = attr["key"] diff --git a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py index bd25f995fe..5298c06371 100644 --- a/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py +++ b/openpype/modules/ftrack/event_handlers_user/action_prepare_project.py @@ -4,10 +4,8 @@ from openpype.api import ProjectSettings from openpype.modules.ftrack.lib import ( BaseAction, - statics_icon -) -from openpype.modules.ftrack.lib.avalon_sync import ( - get_pype_attr, + statics_icon, + get_openpype_attr, CUST_ATTR_AUTO_SYNC ) @@ -162,7 +160,7 @@ class PrepareProjectLocal(BaseAction): for key, entity in project_anatom_settings["attributes"].items(): attribute_values_by_key[key] = entity.value - cust_attrs, hier_cust_attrs = get_pype_attr(self.session, True) + cust_attrs, hier_cust_attrs = get_openpype_attr(self.session, True) for attr in hier_cust_attrs: key = attr["key"] diff --git a/openpype/modules/ftrack/ftrack_module.py b/openpype/modules/ftrack/ftrack_module.py index d242268048..b057503007 100644 --- a/openpype/modules/ftrack/ftrack_module.py +++ b/openpype/modules/ftrack/ftrack_module.py @@ -150,7 +150,7 @@ class FtrackModule( return import ftrack_api - from openpype.modules.ftrack.lib import avalon_sync + from openpype.modules.ftrack.lib import get_openpype_attr session = self.create_ftrack_session() project_entity = session.query( @@ -166,7 +166,7 @@ class FtrackModule( project_id = project_entity["id"] - cust_attr, hier_attr = avalon_sync.get_pype_attr(session) + cust_attr, hier_attr = get_openpype_attr(session) cust_attr_by_key = {attr["key"]: attr for attr in cust_attr} hier_attrs_by_key = {attr["key"]: attr for attr in hier_attr} for key, value in attributes_changes.items(): diff --git a/openpype/modules/ftrack/lib/avalon_sync.py b/openpype/modules/ftrack/lib/avalon_sync.py index 6e83be8b64..cfe1f011e7 100644 --- a/openpype/modules/ftrack/lib/avalon_sync.py +++ b/openpype/modules/ftrack/lib/avalon_sync.py @@ -31,6 +31,7 @@ from .constants import ( CUST_ATTR_AUTO_SYNC, CUST_ATTR_GROUP ) +from .custom_attributes import get_openpype_attr log = Logger.get_logger(__name__) @@ -80,39 +81,6 @@ def join_query_keys(keys): return ",".join(["\"{}\"".format(key) for key in keys]) -def get_pype_attr(session, split_hierarchical=True, query_keys=None): - custom_attributes = [] - hier_custom_attributes = [] - if not query_keys: - query_keys = [ - "id", - "entity_type", - "object_type_id", - "is_hierarchical", - "default" - ] - # TODO remove deprecated "pype" group from query - cust_attrs_query = ( - "select {}" - " from CustomAttributeConfiguration" - # Kept `pype` for Backwards Compatiblity - " where group.name in (\"pype\", \"{}\")" - ).format(", ".join(query_keys), CUST_ATTR_GROUP) - all_avalon_attr = session.query(cust_attrs_query).all() - for cust_attr in all_avalon_attr: - if split_hierarchical and cust_attr["is_hierarchical"]: - hier_custom_attributes.append(cust_attr) - continue - - custom_attributes.append(cust_attr) - - if split_hierarchical: - # return tuple - return custom_attributes, hier_custom_attributes - - return custom_attributes - - def get_python_type_for_custom_attribute(cust_attr, cust_attr_type_name=None): """Python type that should value of custom attribute have. @@ -910,7 +878,7 @@ class SyncEntitiesFactory: def set_cutom_attributes(self): self.log.debug("* Preparing custom attributes") # Get custom attributes and values - custom_attrs, hier_attrs = get_pype_attr( + custom_attrs, hier_attrs = get_openpype_attr( self.session, query_keys=self.cust_attr_query_keys ) ent_types = self.session.query("select id, name from ObjectType").all() @@ -2497,7 +2465,7 @@ class SyncEntitiesFactory: if new_entity_id not in p_chilren: self.entities_dict[parent_id]["children"].append(new_entity_id) - cust_attr, _ = get_pype_attr(self.session) + cust_attr, _ = get_openpype_attr(self.session) for _attr in cust_attr: key = _attr["key"] if key not in av_entity["data"]: From 4996903f23dbc7174270649d88f775c1a1d7a767 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 19:19:41 +0200 Subject: [PATCH 09/23] settings has defined few api exceptions --- openpype/settings/__init__.py | 7 +++++++ openpype/settings/exceptions.py | 11 +++++++++++ openpype/settings/lib.py | 4 ++++ 3 files changed, 22 insertions(+) create mode 100644 openpype/settings/exceptions.py diff --git a/openpype/settings/__init__.py b/openpype/settings/__init__.py index b4187829fc..3755fabeb2 100644 --- a/openpype/settings/__init__.py +++ b/openpype/settings/__init__.py @@ -1,3 +1,7 @@ +from .exceptions import ( + SaveWarning, + SaveSettingsValidation +) from .lib import ( get_system_settings, get_project_settings, @@ -12,6 +16,9 @@ from .entities import ( __all__ = ( + "SaveWarning", + "SaveSettingsValidation", + "get_system_settings", "get_project_settings", "get_current_project_settings", diff --git a/openpype/settings/exceptions.py b/openpype/settings/exceptions.py new file mode 100644 index 0000000000..86f04c76b9 --- /dev/null +++ b/openpype/settings/exceptions.py @@ -0,0 +1,11 @@ +class SaveSettingsValidation(Exception): + pass + + +class SaveWarning(SaveSettingsValidation): + def __init__(self, warnings): + if isinstance(warnings, str): + warnings = [warnings] + self.warnings = warnings + msg = ", ".join(warnings) + super(SaveWarning, self).__init__(msg) diff --git a/openpype/settings/lib.py b/openpype/settings/lib.py index 3bf2141808..31c7c902cb 100644 --- a/openpype/settings/lib.py +++ b/openpype/settings/lib.py @@ -4,6 +4,10 @@ import functools import logging import platform import copy +from .exceptions import ( + SaveSettingsValidation, + SaveWarning +) from .constants import ( M_OVERRIDEN_KEY, M_ENVIRONMENT_KEY, From 9ac5427aaf4e79939d586e3b320e07fed8ea8660 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 20 Apr 2021 19:19:55 +0200 Subject: [PATCH 10/23] ftrack updates custom attributes on application save --- openpype/modules/ftrack/ftrack_module.py | 84 +++++++++++++++++++++++- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/openpype/modules/ftrack/ftrack_module.py b/openpype/modules/ftrack/ftrack_module.py index b057503007..28281786b3 100644 --- a/openpype/modules/ftrack/ftrack_module.py +++ b/openpype/modules/ftrack/ftrack_module.py @@ -1,4 +1,5 @@ import os +import json import collections from abc import ABCMeta, abstractmethod import six @@ -12,6 +13,7 @@ from openpype.modules import ( ILaunchHookPaths, ISettingsChangeListener ) +from openpype.settings import SaveWarning FTRACK_MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -128,10 +130,86 @@ class FtrackModule( if self.tray_module: self.tray_module.changed_user() - def on_system_settings_save(self, *_args, **_kwargs): + def on_system_settings_save(self, old_value, new_value, changes): """Implementation of ISettingsChangeListener interface.""" - # Ignore - return + try: + session = self.create_ftrack_session() + except Exception: + self.log.warning("Couldn't create ftrack session.", exc_info=True) + raise SaveWarning(( + "Couldn't create Ftrack session." + " You may need to update applications" + " and tools in Ftrack custom attributes using defined action." + )) + + from .lib import ( + get_openpype_attr, + CUST_ATTR_APPLICATIONS, + CUST_ATTR_TOOLS, + app_definitions_from_app_manager, + tool_definitions_from_app_manager + ) + from openpype.api import ApplicationManager + query_keys = [ + "id", + "key", + "config" + ] + custom_attributes = get_openpype_attr( + session, + split_hierarchical=False, + query_keys=query_keys + ) + app_attribute = None + tool_attribute = None + for custom_attribute in custom_attributes: + key = custom_attribute["key"] + if key == CUST_ATTR_APPLICATIONS: + app_attribute = custom_attribute + elif key == CUST_ATTR_TOOLS: + tool_attribute = custom_attribute + + app_manager = ApplicationManager(new_value) + missing_attributes = [] + if not app_attribute: + missing_attributes.append(CUST_ATTR_APPLICATIONS) + else: + config = json.loads(app_attribute["config"]) + new_data = app_definitions_from_app_manager(app_manager) + prepared_data = [] + for item in new_data: + for key, label in item.items(): + prepared_data.append({ + "menu": label, + "value": key + }) + + config["data"] = json.dumps(prepared_data) + app_attribute["config"] = json.dumps(config) + + if not tool_attribute: + missing_attributes.append(CUST_ATTR_TOOLS) + else: + config = json.loads(tool_attribute["config"]) + new_data = tool_definitions_from_app_manager(app_manager) + prepared_data = [] + for item in new_data: + for key, label in item.items(): + prepared_data.append({ + "menu": label, + "value": key + }) + config["data"] = json.dumps(prepared_data) + tool_attribute["config"] = json.dumps(config) + + session.commit() + + if missing_attributes: + raise SaveWarning(( + "Couldn't find custom attribute/s ({}) to update." + " You may need to update applications" + " and tools in Ftrack custom attributes using defined action." + ).format(", ".join(missing_attributes))) def on_project_settings_save(self, *_args, **_kwargs): """Implementation of ISettingsChangeListener interface.""" From cc3f483aec706303e68faaa4d7b28a22d8f04b2b Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 11:14:39 +0200 Subject: [PATCH 11/23] removed SaveSettingsValidation from settings init --- openpype/settings/__init__.py | 4 +--- openpype/settings/exceptions.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/openpype/settings/__init__.py b/openpype/settings/__init__.py index 3755fabeb2..78a287f07e 100644 --- a/openpype/settings/__init__.py +++ b/openpype/settings/__init__.py @@ -1,6 +1,5 @@ from .exceptions import ( - SaveWarning, - SaveSettingsValidation + SaveWarning ) from .lib import ( get_system_settings, @@ -17,7 +16,6 @@ from .entities import ( __all__ = ( "SaveWarning", - "SaveSettingsValidation", "get_system_settings", "get_project_settings", diff --git a/openpype/settings/exceptions.py b/openpype/settings/exceptions.py index 86f04c76b9..758a778794 100644 --- a/openpype/settings/exceptions.py +++ b/openpype/settings/exceptions.py @@ -7,5 +7,5 @@ class SaveWarning(SaveSettingsValidation): if isinstance(warnings, str): warnings = [warnings] self.warnings = warnings - msg = ", ".join(warnings) + msg = " | ".join(warnings) super(SaveWarning, self).__init__(msg) From 00c55d0990b25303932ef1453acb2f3435ae37e4 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 11:14:57 +0200 Subject: [PATCH 12/23] save warning are raised afterwards --- openpype/settings/lib.py | 42 +++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/openpype/settings/lib.py b/openpype/settings/lib.py index 31c7c902cb..dd3f79b5b3 100644 --- a/openpype/settings/lib.py +++ b/openpype/settings/lib.py @@ -5,7 +5,6 @@ import logging import platform import copy from .exceptions import ( - SaveSettingsValidation, SaveWarning ) from .constants import ( @@ -118,11 +117,18 @@ def save_studio_settings(data): changes = calculate_changes(old_data, new_data) modules_manager = ModulesManager(_system_settings=new_data) + + warnings = [] for module in modules_manager.get_enabled_modules(): if isinstance(module, ISettingsChangeListener): - module.on_system_settings_save(old_data, new_data, changes) + try: + module.on_system_settings_save(old_data, new_data, changes) + except SaveWarning as exc: + warnings.extend(exc.warnings) - return _SETTINGS_HANDLER.save_studio_settings(data) + _SETTINGS_HANDLER.save_studio_settings(data) + if warnings: + raise SaveWarning(warnings) @require_handler @@ -159,13 +165,20 @@ def save_project_settings(project_name, overrides): changes = calculate_changes(old_data, new_data) modules_manager = ModulesManager() + warnings = [] for module in modules_manager.get_enabled_modules(): if isinstance(module, ISettingsChangeListener): - module.on_project_settings_save( - old_data, new_data, project_name, changes - ) + try: + module.on_project_settings_save( + old_data, new_data, project_name, changes + ) + except SaveWarning as exc: + warnings.extend(exc.warnings) - return _SETTINGS_HANDLER.save_project_settings(project_name, overrides) + _SETTINGS_HANDLER.save_project_settings(project_name, overrides) + + if warnings: + raise SaveWarning(warnings) @require_handler @@ -202,13 +215,20 @@ def save_project_anatomy(project_name, anatomy_data): changes = calculate_changes(old_data, new_data) modules_manager = ModulesManager() + warnings = [] for module in modules_manager.get_enabled_modules(): if isinstance(module, ISettingsChangeListener): - module.on_project_anatomy_save( - old_data, new_data, changes, project_name - ) + try: + module.on_project_anatomy_save( + old_data, new_data, changes, project_name + ) + except SaveWarning as exc: + warnings.extend(exc.warnings) - return _SETTINGS_HANDLER.save_project_anatomy(project_name, anatomy_data) + _SETTINGS_HANDLER.save_project_anatomy(project_name, anatomy_data) + + if warnings: + raise SaveWarning(warnings) @require_handler From d8f84a750d1b65676b228c5db2bbb44d16ae4705 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 11:41:08 +0200 Subject: [PATCH 13/23] ftrack module raise SaveWarning exception if crashes during changing values --- openpype/modules/ftrack/ftrack_module.py | 62 +++++++++++++++++++++--- 1 file changed, 55 insertions(+), 7 deletions(-) diff --git a/openpype/modules/ftrack/ftrack_module.py b/openpype/modules/ftrack/ftrack_module.py index 28281786b3..46403bbc26 100644 --- a/openpype/modules/ftrack/ftrack_module.py +++ b/openpype/modules/ftrack/ftrack_module.py @@ -230,30 +230,45 @@ class FtrackModule( import ftrack_api from openpype.modules.ftrack.lib import get_openpype_attr - session = self.create_ftrack_session() + try: + session = self.create_ftrack_session() + except Exception: + self.log.warning("Couldn't create ftrack session.", exc_info=True) + raise SaveWarning(( + "Couldn't create Ftrack session." + " You may need to update applications" + " and tools in Ftrack custom attributes using defined action." + )) + project_entity = session.query( "Project where full_name is \"{}\"".format(project_name) ).first() if not project_entity: - self.log.warning(( - "Ftrack project with names \"{}\" was not found." + msg = ( + "Ftrack project with names \"{}\" was not found in Ftrack." " Skipping settings attributes change callback." - )) - return + ).format(project_name) + self.log.warning(msg) + raise SaveWarning(msg) project_id = project_entity["id"] cust_attr, hier_attr = get_openpype_attr(session) cust_attr_by_key = {attr["key"]: attr for attr in cust_attr} hier_attrs_by_key = {attr["key"]: attr for attr in hier_attr} + + failed = {} + missing = {} for key, value in attributes_changes.items(): configuration = hier_attrs_by_key.get(key) if not configuration: configuration = cust_attr_by_key.get(key) if not configuration: + missing[key] = value continue + # TODO add add permissions check # TODO add value validations # - value type and list items entity_key = collections.OrderedDict() @@ -267,10 +282,43 @@ class FtrackModule( "value", ftrack_api.symbol.NOT_SET, value - ) ) - session.commit() + try: + session.commit() + self.log.debug( + "Changed project custom attribute \"{}\" to \"{}\"".format( + key, value + ) + ) + except Exception: + self.log.warning( + "Failed to set \"{}\" to \"{}\"".format(key, value), + exc_info=True + ) + session.rollback() + failed[key] = value + + if not failed and not missing: + return + + error_msg = ( + "Values were not updated on Ftrack which may cause issues." + ) + if missing: + error_msg += " Missing Custom attributes on Ftrack: {}.".format( + ", ".join([ + '"{}"'.format(key) + for key in missing.keys() + ]) + ) + if failed: + joined_failed = ", ".join([ + '"{}": "{}"'.format(key, value) + for key, value in failed.items() + ]) + error_msg += " Failed to set: {}".format(joined_failed) + raise SaveWarning(error_msg) def create_ftrack_session(self, **session_kwargs): import ftrack_api From ad64ef3ff95e089c9526aacdeb2f4d86437627e5 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 11:53:28 +0200 Subject: [PATCH 14/23] added some docstrings --- openpype/settings/lib.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/openpype/settings/lib.py b/openpype/settings/lib.py index dd3f79b5b3..c4ed9453f1 100644 --- a/openpype/settings/lib.py +++ b/openpype/settings/lib.py @@ -104,8 +104,14 @@ def save_studio_settings(data): For saving of data cares registered Settings handler. + Warning messages are not logged as module raising them should log it within + it's logger. + Args: data(dict): Overrides data with metadata defying studio overrides. + + Raises: + SaveWarning: If any module raises the exception. """ # Notify Pype modules from openpype.modules import ModulesManager, ISettingsChangeListener @@ -140,10 +146,16 @@ def save_project_settings(project_name, overrides): For saving of data cares registered Settings handler. + Warning messages are not logged as module raising them should log it within + it's logger. + Args: project_name (str): Project name for which overrides are passed. Default project's value is None. overrides(dict): Overrides data with metadata defying studio overrides. + + Raises: + SaveWarning: If any module raises the exception. """ # Notify Pype modules from openpype.modules import ModulesManager, ISettingsChangeListener @@ -190,10 +202,16 @@ def save_project_anatomy(project_name, anatomy_data): For saving of data cares registered Settings handler. + Warning messages are not logged as module raising them should log it within + it's logger. + Args: project_name (str): Project name for which overrides are passed. Default project's value is None. overrides(dict): Overrides data with metadata defying studio overrides. + + Raises: + SaveWarning: If any module raises the exception. """ # Notify Pype modules from openpype.modules import ModulesManager, ISettingsChangeListener From 55dd8f7005785fef10ba7585fa30e2a30af15aed Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 11:53:54 +0200 Subject: [PATCH 15/23] settings gui catch SaveWarning --- .../tools/settings/settings/widgets/categories.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/openpype/tools/settings/settings/widgets/categories.py b/openpype/tools/settings/settings/widgets/categories.py index 9d286485a3..d782aaf54f 100644 --- a/openpype/tools/settings/settings/widgets/categories.py +++ b/openpype/tools/settings/settings/widgets/categories.py @@ -27,7 +27,7 @@ from openpype.settings.entities import ( SchemaError ) -from openpype.settings.lib import get_system_settings +from openpype.settings import SaveWarning from .widgets import ProjectListWidget from . import lib @@ -272,6 +272,15 @@ class SettingsCategoryWidget(QtWidgets.QWidget): # not required. self.reset() + except SaveWarning as exc: + msg = "Settings were saved but few issues happened.\n\n" + msg += "\n".join(exc.warnings) + + dialog = QtWidgets.QMessageBox(self) + dialog.setText(msg) + dialog.setIcon(QtWidgets.QMessageBox.Warning) + dialog.exec_() + except Exception as exc: formatted_traceback = traceback.format_exception(*sys.exc_info()) dialog = QtWidgets.QMessageBox(self) From d9424cdf39ec0657919390a57858c117e3125c26 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 12:08:21 +0200 Subject: [PATCH 16/23] replcaed spaces with new line char --- openpype/modules/ftrack/ftrack_module.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openpype/modules/ftrack/ftrack_module.py b/openpype/modules/ftrack/ftrack_module.py index 46403bbc26..c7ce7d6d07 100644 --- a/openpype/modules/ftrack/ftrack_module.py +++ b/openpype/modules/ftrack/ftrack_module.py @@ -306,7 +306,7 @@ class FtrackModule( "Values were not updated on Ftrack which may cause issues." ) if missing: - error_msg += " Missing Custom attributes on Ftrack: {}.".format( + error_msg += "\nMissing Custom attributes on Ftrack: {}.".format( ", ".join([ '"{}"'.format(key) for key in missing.keys() @@ -317,7 +317,7 @@ class FtrackModule( '"{}": "{}"'.format(key, value) for key, value in failed.items() ]) - error_msg += " Failed to set: {}".format(joined_failed) + error_msg += "\nFailed to set: {}".format(joined_failed) raise SaveWarning(error_msg) def create_ftrack_session(self, **session_kwargs): From b01d541c59ebb9358aaa40855f4507fbd49ff03a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 12:08:36 +0200 Subject: [PATCH 17/23] fixed save warning catch --- .../tools/settings/settings/widgets/categories.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/openpype/tools/settings/settings/widgets/categories.py b/openpype/tools/settings/settings/widgets/categories.py index d782aaf54f..be31a063fe 100644 --- a/openpype/tools/settings/settings/widgets/categories.py +++ b/openpype/tools/settings/settings/widgets/categories.py @@ -273,14 +273,21 @@ class SettingsCategoryWidget(QtWidgets.QWidget): self.reset() except SaveWarning as exc: - msg = "Settings were saved but few issues happened.\n\n" - msg += "\n".join(exc.warnings) + warnings = [ + "Settings were saved but few issues happened." + ] + for item in exc.warnings: + warnings.append(item.replace("\n", "
")) + + msg = "

".join(warnings) dialog = QtWidgets.QMessageBox(self) dialog.setText(msg) dialog.setIcon(QtWidgets.QMessageBox.Warning) dialog.exec_() + self.reset() + except Exception as exc: formatted_traceback = traceback.format_exception(*sys.exc_info()) dialog = QtWidgets.QMessageBox(self) From 4358aace7ef8a8a0f6e5909aa48078405849f1b2 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 12:09:11 +0200 Subject: [PATCH 18/23] ProjectSettings will try to store project settings if anatomy crashes --- openpype/settings/entities/root_entities.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/openpype/settings/entities/root_entities.py b/openpype/settings/entities/root_entities.py index eed3d47f46..05c2b61700 100644 --- a/openpype/settings/entities/root_entities.py +++ b/openpype/settings/entities/root_entities.py @@ -23,6 +23,7 @@ from openpype.settings.constants import ( PROJECT_ANATOMY_KEY, KEY_REGEX ) +from openpype.settings.exceptions import SaveWarning from openpype.settings.lib import ( DEFAULTS_DIR, @@ -724,8 +725,19 @@ class ProjectSettings(RootEntity): project_settings = settings_value.get(PROJECT_SETTINGS_KEY) or {} project_anatomy = settings_value.get(PROJECT_ANATOMY_KEY) or {} - save_project_settings(self.project_name, project_settings) - save_project_anatomy(self.project_name, project_anatomy) + warnings = [] + try: + save_project_settings(self.project_name, project_settings) + except SaveWarning as exc: + warnings.extend(exc.warnings) + + try: + save_project_anatomy(self.project_name, project_anatomy) + except SaveWarning as exc: + warnings.extend(exc.warnings) + + if warnings: + raise SaveWarning(warnings) def _validate_defaults_to_save(self, value): """Valiations of default values before save.""" From 4ba8eb7610e3b95d352e8430222f65bf9b2f6d71 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 12:09:33 +0200 Subject: [PATCH 19/23] defined max length of exc info marks --- openpype/lib/log.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/openpype/lib/log.py b/openpype/lib/log.py index 9745279e28..39b6c67080 100644 --- a/openpype/lib/log.py +++ b/openpype/lib/log.py @@ -123,6 +123,8 @@ class PypeFormatter(logging.Formatter): if record.exc_info is not None: line_len = len(str(record.exc_info[1])) + if line_len > 30: + line_len = 30 out = "{}\n{}\n{}\n{}\n{}".format( out, line_len * "=", From 1418d9734ac5029ccc68ebb328a69b918bae295b Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 12:15:19 +0200 Subject: [PATCH 20/23] added more messages --- openpype/modules/ftrack/ftrack_module.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openpype/modules/ftrack/ftrack_module.py b/openpype/modules/ftrack/ftrack_module.py index c7ce7d6d07..54e92af42c 100644 --- a/openpype/modules/ftrack/ftrack_module.py +++ b/openpype/modules/ftrack/ftrack_module.py @@ -246,8 +246,8 @@ class FtrackModule( if not project_entity: msg = ( - "Ftrack project with names \"{}\" was not found in Ftrack." - " Skipping settings attributes change callback." + "Ftrack project with name \"{}\" was not found in Ftrack." + " Can't push attribute changes." ).format(project_name) self.log.warning(msg) raise SaveWarning(msg) @@ -265,6 +265,9 @@ class FtrackModule( if not configuration: configuration = cust_attr_by_key.get(key) if not configuration: + self.log.warning( + "Custom attribute \"{}\" was not found.".format(key) + ) missing[key] = value continue @@ -304,6 +307,8 @@ class FtrackModule( error_msg = ( "Values were not updated on Ftrack which may cause issues." + " Try to update OpenPype custom attributes and resave" + " project settings." ) if missing: error_msg += "\nMissing Custom attributes on Ftrack: {}.".format( From bfb0874f0399a2e67f8cb389ddea1404329cd53a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 13:35:04 +0200 Subject: [PATCH 21/23] renamed SaveWarning to SaveWarningExc --- openpype/modules/ftrack/ftrack_module.py | 12 +++++------ openpype/settings/__init__.py | 4 ++-- openpype/settings/entities/root_entities.py | 8 ++++---- openpype/settings/exceptions.py | 4 ++-- openpype/settings/lib.py | 20 +++++++++---------- .../settings/settings/widgets/categories.py | 4 ++-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/openpype/modules/ftrack/ftrack_module.py b/openpype/modules/ftrack/ftrack_module.py index 54e92af42c..60eed5c941 100644 --- a/openpype/modules/ftrack/ftrack_module.py +++ b/openpype/modules/ftrack/ftrack_module.py @@ -13,7 +13,7 @@ from openpype.modules import ( ILaunchHookPaths, ISettingsChangeListener ) -from openpype.settings import SaveWarning +from openpype.settings import SaveWarningExc FTRACK_MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) @@ -136,7 +136,7 @@ class FtrackModule( session = self.create_ftrack_session() except Exception: self.log.warning("Couldn't create ftrack session.", exc_info=True) - raise SaveWarning(( + raise SaveWarningExc(( "Couldn't create Ftrack session." " You may need to update applications" " and tools in Ftrack custom attributes using defined action." @@ -205,7 +205,7 @@ class FtrackModule( session.commit() if missing_attributes: - raise SaveWarning(( + raise SaveWarningExc(( "Couldn't find custom attribute/s ({}) to update." " You may need to update applications" " and tools in Ftrack custom attributes using defined action." @@ -234,7 +234,7 @@ class FtrackModule( session = self.create_ftrack_session() except Exception: self.log.warning("Couldn't create ftrack session.", exc_info=True) - raise SaveWarning(( + raise SaveWarningExc(( "Couldn't create Ftrack session." " You may need to update applications" " and tools in Ftrack custom attributes using defined action." @@ -250,7 +250,7 @@ class FtrackModule( " Can't push attribute changes." ).format(project_name) self.log.warning(msg) - raise SaveWarning(msg) + raise SaveWarningExc(msg) project_id = project_entity["id"] @@ -323,7 +323,7 @@ class FtrackModule( for key, value in failed.items() ]) error_msg += "\nFailed to set: {}".format(joined_failed) - raise SaveWarning(error_msg) + raise SaveWarningExc(error_msg) def create_ftrack_session(self, **session_kwargs): import ftrack_api diff --git a/openpype/settings/__init__.py b/openpype/settings/__init__.py index 78a287f07e..e65c89e603 100644 --- a/openpype/settings/__init__.py +++ b/openpype/settings/__init__.py @@ -1,5 +1,5 @@ from .exceptions import ( - SaveWarning + SaveWarningExc ) from .lib import ( get_system_settings, @@ -15,7 +15,7 @@ from .entities import ( __all__ = ( - "SaveWarning", + "SaveWarningExc", "get_system_settings", "get_project_settings", diff --git a/openpype/settings/entities/root_entities.py b/openpype/settings/entities/root_entities.py index 05c2b61700..b89473d9fb 100644 --- a/openpype/settings/entities/root_entities.py +++ b/openpype/settings/entities/root_entities.py @@ -23,7 +23,7 @@ from openpype.settings.constants import ( PROJECT_ANATOMY_KEY, KEY_REGEX ) -from openpype.settings.exceptions import SaveWarning +from openpype.settings.exceptions import SaveWarningExc from openpype.settings.lib import ( DEFAULTS_DIR, @@ -728,16 +728,16 @@ class ProjectSettings(RootEntity): warnings = [] try: save_project_settings(self.project_name, project_settings) - except SaveWarning as exc: + except SaveWarningExc as exc: warnings.extend(exc.warnings) try: save_project_anatomy(self.project_name, project_anatomy) - except SaveWarning as exc: + except SaveWarningExc as exc: warnings.extend(exc.warnings) if warnings: - raise SaveWarning(warnings) + raise SaveWarningExc(warnings) def _validate_defaults_to_save(self, value): """Valiations of default values before save.""" diff --git a/openpype/settings/exceptions.py b/openpype/settings/exceptions.py index 758a778794..a06138eeaf 100644 --- a/openpype/settings/exceptions.py +++ b/openpype/settings/exceptions.py @@ -2,10 +2,10 @@ class SaveSettingsValidation(Exception): pass -class SaveWarning(SaveSettingsValidation): +class SaveWarningExc(SaveSettingsValidation): def __init__(self, warnings): if isinstance(warnings, str): warnings = [warnings] self.warnings = warnings msg = " | ".join(warnings) - super(SaveWarning, self).__init__(msg) + super(SaveWarningExc, self).__init__(msg) diff --git a/openpype/settings/lib.py b/openpype/settings/lib.py index c4ed9453f1..9c05c8e86c 100644 --- a/openpype/settings/lib.py +++ b/openpype/settings/lib.py @@ -5,7 +5,7 @@ import logging import platform import copy from .exceptions import ( - SaveWarning + SaveWarningExc ) from .constants import ( M_OVERRIDEN_KEY, @@ -111,7 +111,7 @@ def save_studio_settings(data): data(dict): Overrides data with metadata defying studio overrides. Raises: - SaveWarning: If any module raises the exception. + SaveWarningExc: If any module raises the exception. """ # Notify Pype modules from openpype.modules import ModulesManager, ISettingsChangeListener @@ -129,12 +129,12 @@ def save_studio_settings(data): if isinstance(module, ISettingsChangeListener): try: module.on_system_settings_save(old_data, new_data, changes) - except SaveWarning as exc: + except SaveWarningExc as exc: warnings.extend(exc.warnings) _SETTINGS_HANDLER.save_studio_settings(data) if warnings: - raise SaveWarning(warnings) + raise SaveWarningExc(warnings) @require_handler @@ -155,7 +155,7 @@ def save_project_settings(project_name, overrides): overrides(dict): Overrides data with metadata defying studio overrides. Raises: - SaveWarning: If any module raises the exception. + SaveWarningExc: If any module raises the exception. """ # Notify Pype modules from openpype.modules import ModulesManager, ISettingsChangeListener @@ -184,13 +184,13 @@ def save_project_settings(project_name, overrides): module.on_project_settings_save( old_data, new_data, project_name, changes ) - except SaveWarning as exc: + except SaveWarningExc as exc: warnings.extend(exc.warnings) _SETTINGS_HANDLER.save_project_settings(project_name, overrides) if warnings: - raise SaveWarning(warnings) + raise SaveWarningExc(warnings) @require_handler @@ -211,7 +211,7 @@ def save_project_anatomy(project_name, anatomy_data): overrides(dict): Overrides data with metadata defying studio overrides. Raises: - SaveWarning: If any module raises the exception. + SaveWarningExc: If any module raises the exception. """ # Notify Pype modules from openpype.modules import ModulesManager, ISettingsChangeListener @@ -240,13 +240,13 @@ def save_project_anatomy(project_name, anatomy_data): module.on_project_anatomy_save( old_data, new_data, changes, project_name ) - except SaveWarning as exc: + except SaveWarningExc as exc: warnings.extend(exc.warnings) _SETTINGS_HANDLER.save_project_anatomy(project_name, anatomy_data) if warnings: - raise SaveWarning(warnings) + raise SaveWarningExc(warnings) @require_handler diff --git a/openpype/tools/settings/settings/widgets/categories.py b/openpype/tools/settings/settings/widgets/categories.py index be31a063fe..e4832c989a 100644 --- a/openpype/tools/settings/settings/widgets/categories.py +++ b/openpype/tools/settings/settings/widgets/categories.py @@ -27,7 +27,7 @@ from openpype.settings.entities import ( SchemaError ) -from openpype.settings import SaveWarning +from openpype.settings import SaveWarningExc from .widgets import ProjectListWidget from . import lib @@ -272,7 +272,7 @@ class SettingsCategoryWidget(QtWidgets.QWidget): # not required. self.reset() - except SaveWarning as exc: + except SaveWarningExc as exc: warnings = [ "Settings were saved but few issues happened." ] From 981443b5c3a789dba845703ea2a512707753db4e Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Wed, 21 Apr 2021 15:15:59 +0200 Subject: [PATCH 22/23] removed unused imports --- openpype/modules/ftrack/lib/avalon_sync.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/openpype/modules/ftrack/lib/avalon_sync.py b/openpype/modules/ftrack/lib/avalon_sync.py index cfe1f011e7..f58e858a5a 100644 --- a/openpype/modules/ftrack/lib/avalon_sync.py +++ b/openpype/modules/ftrack/lib/avalon_sync.py @@ -14,24 +14,21 @@ else: from avalon.api import AvalonMongoDB import avalon + from openpype.api import ( Logger, Anatomy, get_anatomy_settings ) +from openpype.lib import ApplicationManager + +from .constants import CUST_ATTR_ID_KEY +from .custom_attributes import get_openpype_attr from bson.objectid import ObjectId from bson.errors import InvalidId from pymongo import UpdateOne import ftrack_api -from openpype.lib import ApplicationManager - -from .constants import ( - CUST_ATTR_ID_KEY, - CUST_ATTR_AUTO_SYNC, - CUST_ATTR_GROUP -) -from .custom_attributes import get_openpype_attr log = Logger.get_logger(__name__) From 8b00525f9d3da0efe8512513e75af01ed2ca44f3 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Thu, 22 Apr 2021 10:20:56 +0200 Subject: [PATCH 23/23] also pass new values with metadata --- openpype/modules/ftrack/ftrack_module.py | 8 +++++--- openpype/modules/settings_action.py | 8 +++++--- openpype/settings/lib.py | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/openpype/modules/ftrack/ftrack_module.py b/openpype/modules/ftrack/ftrack_module.py index 60eed5c941..848f4cea82 100644 --- a/openpype/modules/ftrack/ftrack_module.py +++ b/openpype/modules/ftrack/ftrack_module.py @@ -130,7 +130,9 @@ class FtrackModule( if self.tray_module: self.tray_module.changed_user() - def on_system_settings_save(self, old_value, new_value, changes): + def on_system_settings_save( + self, old_value, new_value, changes, new_value_metadata + ): """Implementation of ISettingsChangeListener interface.""" try: session = self.create_ftrack_session() @@ -169,7 +171,7 @@ class FtrackModule( elif key == CUST_ATTR_TOOLS: tool_attribute = custom_attribute - app_manager = ApplicationManager(new_value) + app_manager = ApplicationManager(new_value_metadata) missing_attributes = [] if not app_attribute: missing_attributes.append(CUST_ATTR_APPLICATIONS) @@ -217,7 +219,7 @@ class FtrackModule( return def on_project_anatomy_save( - self, old_value, new_value, changes, project_name + self, old_value, new_value, changes, project_name, new_value_metadata ): """Implementation of ISettingsChangeListener interface.""" if not project_name: diff --git a/openpype/modules/settings_action.py b/openpype/modules/settings_action.py index 371e190c12..3f7cb8c3ba 100644 --- a/openpype/modules/settings_action.py +++ b/openpype/modules/settings_action.py @@ -16,18 +16,20 @@ class ISettingsChangeListener: } """ @abstractmethod - def on_system_settings_save(self, old_value, new_value, changes): + def on_system_settings_save( + self, old_value, new_value, changes, new_value_metadata + ): pass @abstractmethod def on_project_settings_save( - self, old_value, new_value, changes, project_name + self, old_value, new_value, changes, project_name, new_value_metadata ): pass @abstractmethod def on_project_anatomy_save( - self, old_value, new_value, changes, project_name + self, old_value, new_value, changes, project_name, new_value_metadata ): pass diff --git a/openpype/settings/lib.py b/openpype/settings/lib.py index 9c05c8e86c..f61166fa69 100644 --- a/openpype/settings/lib.py +++ b/openpype/settings/lib.py @@ -119,6 +119,7 @@ def save_studio_settings(data): old_data = get_system_settings() default_values = get_default_settings()[SYSTEM_SETTINGS_KEY] new_data = apply_overrides(default_values, copy.deepcopy(data)) + new_data_with_metadata = copy.deepcopy(new_data) clear_metadata_from_settings(new_data) changes = calculate_changes(old_data, new_data) @@ -128,7 +129,9 @@ def save_studio_settings(data): for module in modules_manager.get_enabled_modules(): if isinstance(module, ISettingsChangeListener): try: - module.on_system_settings_save(old_data, new_data, changes) + module.on_system_settings_save( + old_data, new_data, changes, new_data_with_metadata + ) except SaveWarningExc as exc: warnings.extend(exc.warnings) @@ -173,6 +176,7 @@ def save_project_settings(project_name, overrides): old_data = get_default_project_settings(exclude_locals=True) new_data = apply_overrides(default_values, copy.deepcopy(overrides)) + new_data_with_metadata = copy.deepcopy(new_data) clear_metadata_from_settings(new_data) changes = calculate_changes(old_data, new_data) @@ -182,7 +186,11 @@ def save_project_settings(project_name, overrides): if isinstance(module, ISettingsChangeListener): try: module.on_project_settings_save( - old_data, new_data, project_name, changes + old_data, + new_data, + project_name, + changes, + new_data_with_metadata ) except SaveWarningExc as exc: warnings.extend(exc.warnings) @@ -229,6 +237,7 @@ def save_project_anatomy(project_name, anatomy_data): old_data = get_default_anatomy_settings(exclude_locals=True) new_data = apply_overrides(default_values, copy.deepcopy(anatomy_data)) + new_data_with_metadata = copy.deepcopy(new_data) clear_metadata_from_settings(new_data) changes = calculate_changes(old_data, new_data) @@ -238,7 +247,11 @@ def save_project_anatomy(project_name, anatomy_data): if isinstance(module, ISettingsChangeListener): try: module.on_project_anatomy_save( - old_data, new_data, changes, project_name + old_data, + new_data, + changes, + project_name, + new_data_with_metadata ) except SaveWarningExc as exc: warnings.extend(exc.warnings)