From ec9647c7cd70a70b1a3d115a849bb4cf7789ef06 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Thu, 28 Nov 2024 00:48:18 +0200 Subject: [PATCH] move `simple_creators` and `editorial_creators` to a better place and implement conversion --- .../plugins/create/create_editorial.py | 2 +- .../plugins/create/create_from_settings.py | 2 +- server/__init__.py | 20 ++++++++++- server/settings/__init__.py | 3 ++ server/settings/conversion.py | 34 +++++++++++++++++++ server/settings/creator_plugins.py | 19 +++++++++++ server/settings/main.py | 19 +---------- 7 files changed, 78 insertions(+), 21 deletions(-) create mode 100644 server/settings/conversion.py diff --git a/client/ayon_traypublisher/plugins/create/create_editorial.py b/client/ayon_traypublisher/plugins/create/create_editorial.py index e2cda49..40a6f1b 100644 --- a/client/ayon_traypublisher/plugins/create/create_editorial.py +++ b/client/ayon_traypublisher/plugins/create/create_editorial.py @@ -200,7 +200,7 @@ def __init__(self, *args, **kwargs): def apply_settings(self, project_settings): editorial_creators = deepcopy( - project_settings["traypublisher"]["editorial_creators"] + project_settings["traypublisher"]["create"]["editorial_creators"] ) creator_settings = editorial_creators.get(self.identifier) diff --git a/client/ayon_traypublisher/plugins/create/create_from_settings.py b/client/ayon_traypublisher/plugins/create/create_from_settings.py index 13cf92a..7dfe5ee 100644 --- a/client/ayon_traypublisher/plugins/create/create_from_settings.py +++ b/client/ayon_traypublisher/plugins/create/create_from_settings.py @@ -11,7 +11,7 @@ def initialize(): project_name = os.environ["AYON_PROJECT_NAME"] project_settings = get_project_settings(project_name) - simple_creators = project_settings["traypublisher"]["simple_creators"] + simple_creators = project_settings["traypublisher"]["create"]["simple_creators"] global_variables = globals() for item in simple_creators: diff --git a/server/__init__.py b/server/__init__.py index 830f325..3113cb9 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -1,6 +1,12 @@ +from typing import Any + from ayon_server.addons import BaseServerAddon -from .settings import TraypublisherSettings, DEFAULT_TRAYPUBLISHER_SETTING +from .settings import ( + TraypublisherSettings, + DEFAULT_TRAYPUBLISHER_SETTING, + convert_settings_overrides, +) class Traypublisher(BaseServerAddon): @@ -9,3 +15,15 @@ class Traypublisher(BaseServerAddon): async def get_default_settings(self): settings_model_cls = self.get_settings_model() return settings_model_cls(**DEFAULT_TRAYPUBLISHER_SETTING) + + async def convert_settings_overrides( + self, + source_version: str, + overrides: dict[str, Any], + ) -> dict[str, Any]: + convert_settings_overrides(source_version, overrides) + # Use super conversion + return await super().convert_settings_overrides( + source_version, overrides + ) + diff --git a/server/settings/__init__.py b/server/settings/__init__.py index bcf8bef..eddc54f 100644 --- a/server/settings/__init__.py +++ b/server/settings/__init__.py @@ -2,9 +2,12 @@ TraypublisherSettings, DEFAULT_TRAYPUBLISHER_SETTING, ) +from .conversion import convert_settings_overrides __all__ = ( "TraypublisherSettings", "DEFAULT_TRAYPUBLISHER_SETTING", + + "convert_settings_overrides", ) diff --git a/server/settings/conversion.py b/server/settings/conversion.py new file mode 100644 index 0000000..7de2d42 --- /dev/null +++ b/server/settings/conversion.py @@ -0,0 +1,34 @@ +from typing import Any + + +def _convert_simple_creators_0_2_9(overrides): + if "simple_creators" not in overrides: + return + + if overrides.get("create") is None: + overrides.update({ + "create": {} + }) + + overrides["create"]["simple_creators"] = overrides.pop("simple_creators") + + +def _convert_editorial_creators_0_2_9(overrides): + if "editorial_creators" not in overrides: + return + + if overrides.get("create") is None: + overrides.update({ + "create": {} + }) + + overrides["create"]["editorial_creators"] = overrides.pop("editorial_creators") + + +def convert_settings_overrides( + source_version: str, + overrides: dict[str, Any], +) -> dict[str, Any]: + _convert_simple_creators_0_2_9(overrides) + _convert_editorial_creators_0_2_9(overrides) + return overrides diff --git a/server/settings/creator_plugins.py b/server/settings/creator_plugins.py index a618d06..00bd600 100644 --- a/server/settings/creator_plugins.py +++ b/server/settings/creator_plugins.py @@ -8,6 +8,15 @@ from ayon_server.settings.validators import ensure_unique_names from ayon_server.exceptions import BadRequestException +from .simple_creators import ( + SimpleCreatorPlugin, + DEFAULT_SIMPLE_CREATORS, +) +from .editorial_creators import ( + TraypublisherEditorialCreatorPlugins, + DEFAULT_EDITORIAL_CREATORS, +) + class BatchMovieCreatorPlugin(BaseSettingsModel): """Allows to publish multiple video files in one go.
Name of matching @@ -229,13 +238,23 @@ class TrayPublisherCreatePluginsModel(BaseSettingsModel): title="Batch Movie Creator", default_factory=BatchMovieCreatorPlugin ) + editorial_creators: TraypublisherEditorialCreatorPlugins = SettingsField( + title="Editorial Creators", + default_factory=TraypublisherEditorialCreatorPlugins, + ) IngestCSV: IngestCSVPluginModel = SettingsField( title="Ingest CSV", default_factory=IngestCSVPluginModel ) + simple_creators: list[SimpleCreatorPlugin] = SettingsField( + title="Simple Create Plugins", + default_factory=SimpleCreatorPlugin, + ) DEFAULT_CREATORS = { + "simple_creators": DEFAULT_SIMPLE_CREATORS, + "editorial_creators": DEFAULT_EDITORIAL_CREATORS, "BatchMovieCreator": { "default_variants": [ "Main" diff --git a/server/settings/main.py b/server/settings/main.py index 760c529..6723993 100644 --- a/server/settings/main.py +++ b/server/settings/main.py @@ -1,14 +1,7 @@ from ayon_server.settings import BaseSettingsModel, SettingsField from .imageio import TrayPublisherImageIOModel -from .simple_creators import ( - SimpleCreatorPlugin, - DEFAULT_SIMPLE_CREATORS, -) -from .editorial_creators import ( - TraypublisherEditorialCreatorPlugins, - DEFAULT_EDITORIAL_CREATORS, -) + from .creator_plugins import ( TrayPublisherCreatePluginsModel, DEFAULT_CREATORS, @@ -25,14 +18,6 @@ class TraypublisherSettings(BaseSettingsModel): default_factory=TrayPublisherImageIOModel, title="Color Management (ImageIO)" ) - simple_creators: list[SimpleCreatorPlugin] = SettingsField( - title="Simple Create Plugins", - default_factory=SimpleCreatorPlugin, - ) - editorial_creators: TraypublisherEditorialCreatorPlugins = SettingsField( - title="Editorial Creators", - default_factory=TraypublisherEditorialCreatorPlugins, - ) create: TrayPublisherCreatePluginsModel = SettingsField( title="Create", default_factory=TrayPublisherCreatePluginsModel @@ -44,8 +29,6 @@ class TraypublisherSettings(BaseSettingsModel): DEFAULT_TRAYPUBLISHER_SETTING = { - "simple_creators": DEFAULT_SIMPLE_CREATORS, - "editorial_creators": DEFAULT_EDITORIAL_CREATORS, "create": DEFAULT_CREATORS, "publish": DEFAULT_PUBLISH_PLUGINS, }