diff --git a/plugins/VersionUpgrade/VersionUpgrade54to55/VersionUpgrade54to55.py b/plugins/VersionUpgrade/VersionUpgrade54to55/VersionUpgrade54to55.py new file mode 100644 index 0000000000..a65a938320 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade54to55/VersionUpgrade54to55.py @@ -0,0 +1,75 @@ +# Copyright (c) 2023 UltiMaker +# Cura is released under the terms of the LGPLv3 or higher. + +import configparser +from typing import Tuple, List +import io +from UM.VersionUpgrade import VersionUpgrade +import re + + + +class VersionUpgrade54to55(VersionUpgrade): + profile_regex = re.compile( + r"um\_(?Ps(3|5|7))_(?Paa|cc|bb)(?P0\.(6|4|8))_(?Ppla|petg|abs)_(?P0\.\d{1,2}mm)") + + @staticmethod + def _isUpgradedUltimakerDefinitionId(definition_id: str) -> bool: + if definition_id.startswith("ultimaker_s5"): + return True + if definition_id.startswith("ultimaker_s3"): + return True + if definition_id.startswith("ultimaker_s7"): + return True + + return False + + @staticmethod + def _isBrandedMaterialID(material_id): + return material_id.startswith("ultimaker_") + + + + @staticmethod + def upgradeStack(serialized: str, filename: str) -> Tuple[List[str], List[str]]: + """ + Upgrades stacks to have the new version number. + + :param serialized: The original contents of the stack. + :param filename: The original file name of the stack. + :return: A list of new file names, and a list of the new contents for + those files. + """ + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialized) + + # Update version number. + if "general" not in parser: + parser["general"] = {} + + extruder_definition_id = parser["containers"]["7"] + if parser["metadata"]["type"] == "extruder_train" and VersionUpgrade54to55._isUpgradedUltimakerDefinitionId(extruder_definition_id): + # We only need to update certain Ultimaker extruder ID's + material_id = parser["containers"]["4"] + quality_id = parser["containers"]["3"] + intent_id = parser["containers"]["2"] + if VersionUpgrade54to55._isBrandedMaterialID(material_id): + # We have an Ultimaker branded material ID, so we should change the intent & quality! + + quality_id = VersionUpgrade54to55.profile_regex.sub( + "um_\g_\g\g_um-\g_\g", quality_id) + + + intent_id = VersionUpgrade54to55.profile_regex.sub( + "um_\g_\g\g_um-\g_\g", intent_id) + + + parser["containers"]["3"] = quality_id + parser["containers"]["2"] = intent_id + + # We're not changing any settings, but we are changing how certain stacks are handled. + parser["general"]["version"] = "6" + + result = io.StringIO() + parser.write(result) + return [filename], [result.getvalue()] diff --git a/plugins/VersionUpgrade/VersionUpgrade54to55/__init__.py b/plugins/VersionUpgrade/VersionUpgrade54to55/__init__.py new file mode 100644 index 0000000000..b1e1904f56 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade54to55/__init__.py @@ -0,0 +1,35 @@ +# Copyright (c) 2023 UltiMaker +# Cura is released under the terms of the LGPLv3 or higher. + +from typing import Any, Dict, TYPE_CHECKING + +from . import VersionUpgrade54to55 + +if TYPE_CHECKING: + from UM.Application import Application + +upgrade = VersionUpgrade54to55.VersionUpgrade54to55() + + +def getMetaData() -> Dict[str, Any]: + return { + "version_upgrade": { + # From To Upgrade function + ("machine_stack", 5000022): ("machine_stack", 6000022, upgrade.upgradeStack), + ("extruder_train", 5000022): ("extruder_train", 6000022, upgrade.upgradeStack), + }, + "sources": { + "machine_stack": { + "get_version": upgrade.getCfgVersion, + "location": {"./machine_instances"} + }, + "extruder_train": { + "get_version": upgrade.getCfgVersion, + "location": {"./extruders"} + } + } + } + + +def register(app: "Application") -> Dict[str, Any]: + return {"version_upgrade": upgrade} diff --git a/plugins/VersionUpgrade/VersionUpgrade54to55/plugin.json b/plugins/VersionUpgrade/VersionUpgrade54to55/plugin.json new file mode 100644 index 0000000000..9936564358 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade54to55/plugin.json @@ -0,0 +1,8 @@ +{ + "name": "Version Upgrade 5.3 to 5.4", + "author": "UltiMaker", + "version": "1.0.0", + "description": "Upgrades configurations from Cura 5.4 to Cura 5.5.", + "api": 8, + "i18n-catalog": "cura" +}