diff options
3 files changed, 141 insertions, 0 deletions
diff --git a/plugins/VersionUpgrade/VersionUpgrade45to46/VersionUpgrade45to46.py b/plugins/VersionUpgrade/VersionUpgrade45to46/VersionUpgrade45to46.py new file mode 100644 index 0000000000..378e1fd5d7 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade45to46/VersionUpgrade45to46.py @@ -0,0 +1,74 @@ +# Copyright (c) 2020 Ultimaker B.V. +# 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 + +_removed_settings = { + "machine_filament_park_distance" +} + +class VersionUpgrade45to46(VersionUpgrade): + def getCfgVersion(self, serialised: str) -> int: + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialised) + format_version = int(parser.get("general", "version")) # Explicitly give an exception when this fails. That means that the file format is not recognised. + setting_version = int(parser.get("metadata", "setting_version", fallback = "0")) + return format_version * 1000000 + setting_version + + ## Upgrades Preferences to have the new version number. + # + # This renames the renamed settings in the list of visible settings. + def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]: + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialized) + + # Update version number. + parser["metadata"]["setting_version"] = "12" + + # Remove deleted settings from the visible settings list. + visible_settings = set(parser["general"]["visible_settings"].split(";")) + for removed in _removed_settings: + if removed in visible_settings: + visible_settings.remove(removed) + parser["general"]["visible_settings"] = ";".join(visible_settings) + + result = io.StringIO() + parser.write(result) + return [filename], [result.getvalue()] + + ## Upgrades instance containers to have the new version + # number. + # + # This renames the renamed settings in the containers. + def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]: + parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ()) + parser.read_string(serialized) + + # Update version number. + parser["metadata"]["setting_version"] = "12" + + if "values" in parser: + for removed in _removed_settings: + if removed in parser["values"]: + del parser["values"][removed] + + result = io.StringIO() + parser.write(result) + return [filename], [result.getvalue()] + + ## Upgrades stacks to have the new version number. + def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]: + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialized) + + # Update version number. + if "metadata" not in parser: + parser["metadata"] = {} + parser["metadata"]["setting_version"] = "12" + + result = io.StringIO() + parser.write(result) + return [filename], [result.getvalue()] diff --git a/plugins/VersionUpgrade/VersionUpgrade45to46/__init__.py b/plugins/VersionUpgrade/VersionUpgrade45to46/__init__.py new file mode 100644 index 0000000000..e44a02f704 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade45to46/__init__.py @@ -0,0 +1,59 @@ +# Copyright (c) 2020 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + +from typing import Any, Dict, TYPE_CHECKING + +from . import VersionUpgrade45to46 + +if TYPE_CHECKING: + from UM.Application import Application + +upgrade = VersionUpgrade45to46.VersionUpgrade45to46() + +def getMetaData() -> Dict[str, Any]: + return { + "version_upgrade": { + # From To Upgrade function + ("preferences", 6000011): ("preferences", 6000012, upgrade.upgradePreferences), + ("machine_stack", 4000011): ("machine_stack", 4000012, upgrade.upgradeStack), + ("extruder_train", 4000011): ("extruder_train", 4000012, upgrade.upgradeStack), + ("definition_changes", 4000011): ("definition_changes", 4000012, upgrade.upgradeInstanceContainer), + ("quality_changes", 4000011): ("quality_changes", 4000012, upgrade.upgradeInstanceContainer), + ("quality", 4000011): ("quality", 4000012, upgrade.upgradeInstanceContainer), + ("user", 4000011): ("user", 4000012, upgrade.upgradeInstanceContainer), + }, + "sources": { + "preferences": { + "get_version": upgrade.getCfgVersion, + "location": {"."} + }, + "machine_stack": { + "get_version": upgrade.getCfgVersion, + "location": {"./machine_instances"} + }, + "extruder_train": { + "get_version": upgrade.getCfgVersion, + "location": {"./extruders"} + }, + "definition_changes": { + "get_version": upgrade.getCfgVersion, + "location": {"./definition_changes"} + }, + "quality_changes": { + "get_version": upgrade.getCfgVersion, + "location": {"./quality_changes"} + }, + "quality": { + "get_version": upgrade.getCfgVersion, + "location": {"./quality"} + }, + "user": { + "get_version": upgrade.getCfgVersion, + "location": {"./user"} + } + } + } + + +def register(app: "Application") -> Dict[str, Any]: + return {"version_upgrade": upgrade} diff --git a/plugins/VersionUpgrade/VersionUpgrade45to46/plugin.json b/plugins/VersionUpgrade/VersionUpgrade45to46/plugin.json new file mode 100644 index 0000000000..ceabdb6d9d --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade45to46/plugin.json @@ -0,0 +1,8 @@ +{ + "name": "Version Upgrade 4.5 to 4.6", + "author": "Ultimaker B.V.", + "version": "1.0.0", + "description": "Upgrades configurations from Cura 4.5 to Cura 4.6.", + "api": "7.1", + "i18n-catalog": "cura" +} |