Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaime van Kessel <nallath@gmail.com>2019-07-23 12:15:13 +0300
committerJaime van Kessel <nallath@gmail.com>2019-07-23 12:15:13 +0300
commite56e355e7963c015046f271e6e50a09c952b8170 (patch)
treead57661f0ee7a8ddbaa3b5965cebbca3a0950111 /plugins/VersionUpgrade/VersionUpgrade42to43
parent203ea2a83fa6c56311f5e1baca7f0307123a253d (diff)
Added upgrader for 4.3
Diffstat (limited to 'plugins/VersionUpgrade/VersionUpgrade42to43')
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade42to43/VersionUpgrade42to43.py72
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade42to43/__init__.py54
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade42to43/plugin.json8
3 files changed, 134 insertions, 0 deletions
diff --git a/plugins/VersionUpgrade/VersionUpgrade42to43/VersionUpgrade42to43.py b/plugins/VersionUpgrade/VersionUpgrade42to43/VersionUpgrade42to43.py
new file mode 100644
index 0000000000..035d53ee02
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade42to43/VersionUpgrade42to43.py
@@ -0,0 +1,72 @@
+import configparser
+import io
+from typing import Tuple, List
+
+from UM.VersionUpgrade import VersionUpgrade
+
+_renamed_profiles = { }
+
+
+## Upgrades configurations from the state they were in at version 4.2 to the
+# state they should be in at version 4.3.
+class VersionUpgrade42to43(VersionUpgrade):
+ ## Gets the version number from a CFG file in Uranium's 4.2 format.
+ #
+ # Since the format may change, this is implemented for the 4.2 format only
+ # and needs to be included in the version upgrade system rather than
+ # globally in Uranium.
+ #
+ # \param serialised The serialised form of a CFG file.
+ # \return The version number stored in the CFG file.
+ # \raises ValueError The format of the version number in the file is
+ # incorrect.
+ # \raises KeyError The format of the file is incorrect.
+ 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 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)
+ parser.read_string(serialized)
+
+ # Update version number.
+ parser["metadata"]["setting_version"] = "9"
+
+ 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.
+ parser["metadata"]["setting_version"] = "9"
+ # Handle changes for the imade3d jellybox. The machine was split up into parts (eg; a 2 fan version and a single
+ # fan version. Perviously it used variants for this. The only upgrade we can do here is strip that variant.
+ # This is because we only upgrade per stack (and to fully do these changes, we'd need to switch out something
+ # in the global container based on changes made to the extruder stack)
+ if parser["containers"]["6"] == "imade3d_jellybox_extruder_0":
+ quality_id = parser["containers"]["2"]
+ if quality_id.endswith("_2-fans"):
+ parser["containers"]["2"] = quality_id.replace("_2-fans", "")
+
+ material_id = parser["containers"]["3"]
+ if material_id.endswith("_2-fans"):
+ parser["containers"]["3"] = material_id.replace("_2-fans", "")
+ variant_id = parser["containers"]["4"]
+
+ if variant_id.endswith("_2-fans"):
+ parser["containers"]["4"] = variant_id.replace("_2-fans", "")
+
+ result = io.StringIO()
+ parser.write(result)
+ return [filename], [result.getvalue()] \ No newline at end of file
diff --git a/plugins/VersionUpgrade/VersionUpgrade42to43/__init__.py b/plugins/VersionUpgrade/VersionUpgrade42to43/__init__.py
new file mode 100644
index 0000000000..d29f8e7833
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade42to43/__init__.py
@@ -0,0 +1,54 @@
+# Copyright (c) 2019 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+from typing import Any, Dict, TYPE_CHECKING
+
+from . import VersionUpgrade42to43
+
+if TYPE_CHECKING:
+ from UM.Application import Application
+
+upgrade = VersionUpgrade42to43.VersionUpgrade42to43()
+
+def getMetaData() -> Dict[str, Any]:
+ return {
+ "version_upgrade": {
+ # From To Upgrade function
+ ("machine_stack", 4000008): ("machine_stack", 4000009, upgrade.upgradeStack),
+ ("extruder_train", 4000008): ("extruder_train", 4000009, upgrade.upgradeStack),
+ ("definition_changes", 4000008): ("definition_changes", 4000009, upgrade.upgradeInstanceContainer),
+ ("quality_changes", 4000008): ("quality_changes", 4000009, upgrade.upgradeInstanceContainer),
+ ("quality", 4000008): ("quality", 4000009, upgrade.upgradeInstanceContainer),
+ ("user", 4000008): ("user", 4000009, upgrade.upgradeInstanceContainer),
+ },
+ "sources": {
+ "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 } \ No newline at end of file
diff --git a/plugins/VersionUpgrade/VersionUpgrade42to43/plugin.json b/plugins/VersionUpgrade/VersionUpgrade42to43/plugin.json
new file mode 100644
index 0000000000..339ec67ee7
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade42to43/plugin.json
@@ -0,0 +1,8 @@
+{
+ "name": "Version Upgrade 4.2 to 4.3",
+ "author": "Ultimaker B.V.",
+ "version": "1.0.0",
+ "description": "Upgrades configurations from Cura 4.2 to Cura 4.3.",
+ "api": "6.0",
+ "i18n-catalog": "cura"
+}