Browse Source

Added upgrader for 4.3

Jaime van Kessel 5 years ago
parent
commit
e56e355e79

+ 1 - 1
cura/CuraApplication.py

@@ -144,7 +144,7 @@ class CuraApplication(QtApplication):
     # SettingVersion represents the set of settings available in the machine/extruder definitions.
     # You need to make sure that this version number needs to be increased if there is any non-backwards-compatible
     # changes of the settings.
-    SettingVersion = 8
+    SettingVersion = 9
 
     Created = False
 

+ 72 - 0
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()]

+ 54 - 0
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 }

+ 8 - 0
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"
+}

+ 1 - 1
resources/definitions/fdmextruder.def.json

@@ -6,7 +6,7 @@
         "type": "extruder",
         "author": "Ultimaker",
         "manufacturer": "Unknown",
-        "setting_version": 8,
+        "setting_version": 9,
         "visible": false,
         "position": "0"
     },

+ 1 - 1
resources/definitions/fdmprinter.def.json

@@ -7,7 +7,7 @@
         "author": "Ultimaker",
         "category": "Other",
         "manufacturer": "Unknown",
-        "setting_version": 8,
+        "setting_version": 9,
         "file_formats": "text/x-gcode;application/x-stl-ascii;application/x-stl-binary;application/x-wavefront-obj;application/x3g",
         "visible": false,
         "has_materials": true,

+ 0 - 1
resources/definitions/geeetech_a30.def.json

@@ -6,7 +6,6 @@
     "metadata": {
         "author": "William & Cataldo URSO",
         "manufacturer": "Shenzhen Geeetech Technology",
-        "setting_version": 8,
         "file_formats": "text/x-gcode",
         "visible": true,
         "has_materials": true,

+ 1 - 1
resources/quality/abax_pri3/apri3_pla_fast.inst.cfg

@@ -4,7 +4,7 @@ name = Fine
 definition = abax_pri3
 
 [metadata]
-setting_version = 8
+setting_version = 9
 type = quality
 quality_type = normal
 weight = 0

+ 1 - 1
resources/quality/abax_pri3/apri3_pla_high.inst.cfg

@@ -4,7 +4,7 @@ name = Extra Fine
 definition = abax_pri3
 
 [metadata]
-setting_version = 8
+setting_version = 9
 type = quality
 quality_type = high
 weight = 1

+ 1 - 1
resources/quality/abax_pri3/apri3_pla_normal.inst.cfg

@@ -4,7 +4,7 @@ name = Fine
 definition = abax_pri3
 
 [metadata]
-setting_version = 8
+setting_version = 9
 type = quality
 quality_type = normal
 weight = 0

Some files were not shown because too many files changed in this diff