From ac995dffc1368681871c1ec24edecaabc6f3e023 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Mon, 27 May 2024 12:17:13 +0200 Subject: [PATCH] moved conversion functions to settings --- server/__init__.py | 47 ++++--------------------------- server/settings/__init__.py | 3 ++ server/settings/conversion.py | 52 +++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 server/settings/conversion.py diff --git a/server/__init__.py b/server/__init__.py index 79f505ccd5..d60f50f471 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -2,7 +2,11 @@ from typing import Any from ayon_server.addons import BaseServerAddon -from .settings import CoreSettings, DEFAULT_VALUES +from .settings import ( + CoreSettings, + DEFAULT_VALUES, + convert_settings_overrides, +) class CoreAddon(BaseServerAddon): @@ -17,47 +21,8 @@ class CoreAddon(BaseServerAddon): source_version: str, overrides: dict[str, Any], ) -> dict[str, Any]: - self._convert_imagio_configs_0_3_1(overrides) + convert_settings_overrides(source_version, overrides) # Use super conversion return await super().convert_settings_overrides( source_version, overrides ) - - def _convert_imagio_configs_0_3_1(self, overrides): - """Imageio config settings did change to profiles since 0.3.1. .""" - imageio_overrides = overrides.get("imageio") or {} - if ( - "ocio_config" not in imageio_overrides - or "filepath" not in imageio_overrides["ocio_config"] - ): - return - - ocio_config = imageio_overrides.pop("ocio_config") - - filepath = ocio_config["filepath"] - if not filepath: - return - first_filepath = filepath[0] - ocio_config_profiles = imageio_overrides.setdefault( - "ocio_config_profiles", [] - ) - base_value = { - "type": "builtin_path", - "product_name": "", - "host_names": [], - "task_names": [], - "task_types": [], - "custom_path": "", - "builtin_path": "{BUILTIN_OCIO_ROOT}/aces_1.2/config.ocio" - } - if first_filepath in ( - "{BUILTIN_OCIO_ROOT}/aces_1.2/config.ocio", - "{BUILTIN_OCIO_ROOT}/nuke-default/config.ocio", - ): - base_value["type"] = "builtin_path" - base_value["builtin_path"] = first_filepath - else: - base_value["type"] = "custom_path" - base_value["custom_path"] = first_filepath - - ocio_config_profiles.append(base_value) diff --git a/server/settings/__init__.py b/server/settings/__init__.py index 527a2bdc0c..4bb21a9644 100644 --- a/server/settings/__init__.py +++ b/server/settings/__init__.py @@ -1,7 +1,10 @@ from .main import CoreSettings, DEFAULT_VALUES +from .conversion import convert_settings_overrides __all__ = ( "CoreSettings", "DEFAULT_VALUES", + + "convert_settings_overrides", ) diff --git a/server/settings/conversion.py b/server/settings/conversion.py new file mode 100644 index 0000000000..74046fe020 --- /dev/null +++ b/server/settings/conversion.py @@ -0,0 +1,52 @@ +import copy +from typing import Any + +from .publish_plugins import DEFAULT_PUBLISH_VALUES + + +def _convert_imageio_configs_0_3_1(overrides): + """Imageio config settings did change to profiles since 0.3.1. .""" + imageio_overrides = overrides.get("imageio") or {} + if ( + "ocio_config" not in imageio_overrides + or "filepath" not in imageio_overrides["ocio_config"] + ): + return + + ocio_config = imageio_overrides.pop("ocio_config") + + filepath = ocio_config["filepath"] + if not filepath: + return + first_filepath = filepath[0] + ocio_config_profiles = imageio_overrides.setdefault( + "ocio_config_profiles", [] + ) + base_value = { + "type": "builtin_path", + "product_name": "", + "host_names": [], + "task_names": [], + "task_types": [], + "custom_path": "", + "builtin_path": "{BUILTIN_OCIO_ROOT}/aces_1.2/config.ocio" + } + if first_filepath in ( + "{BUILTIN_OCIO_ROOT}/aces_1.2/config.ocio", + "{BUILTIN_OCIO_ROOT}/nuke-default/config.ocio", + ): + base_value["type"] = "builtin_path" + base_value["builtin_path"] = first_filepath + else: + base_value["type"] = "custom_path" + base_value["custom_path"] = first_filepath + + ocio_config_profiles.append(base_value) + + +def convert_settings_overrides( + source_version: str, + overrides: dict[str, Any], +) -> dict[str, Any]: + _convert_imageio_configs_0_3_1(overrides) + return overrides