Browse Source

Add boilerplate version upgrade plug-in

This plug-in does nothing at the moment. It merely says that it is able to upgrade configuration from version 2.1 to 2.2, but then raises exceptions when you actually try to use it. This is by design. I will now implement the functions that do the conversion.

Contributes to issue CURA-844.
Ghostkeeper 9 years ago
parent
commit
2f4e63a944

+ 21 - 0
plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py

@@ -0,0 +1,21 @@
+# Copyright (c) 2015 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+##  Creates a new machine instance instance by parsing a serialised machine
+#   instance in version 1 of the file format.
+#
+#   \param serialised The serialised form of a machine instance in version 1.
+#   \return A machine instance instance, or None if the file format is
+#   incorrect.
+def importVersion1(serialised):
+    return None #Not implemented yet.
+
+##  A representation of a machine instance used as intermediary form for
+#   conversion from one format to the other.
+class MachineInstance:
+    ##  Serialises this machine instance as file format version 2.
+    #
+    #   \return A serialised form of this machine instance, serialised in
+    #   version 2 of the file format.
+    def exportVersion2():
+        raise Exception("Not implemented yet.")

+ 20 - 0
plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py

@@ -0,0 +1,20 @@
+# Copyright (c) 2015 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+##  Creates a new preferences instance by parsing a serialised preferences file
+#   in version 2 of the file format.
+#
+#   \param serialised The serialised form of a preferences file in version 2.
+#   \return A preferences instance, or None if the file format is incorrect.
+def importVersion2(serialised):
+    return None #Not implemented yet.
+
+##  A representation of a preferences file used as intermediary form for
+#   conversion from one format to the other.
+class Preferences:
+    ##  Serialises this preferences file as file format version 3.
+    #
+    #   \return A serialised form of this preferences file, serialised in
+    #   version 3 of the file format.
+    def exportVersion3():
+        raise Exception("Not implemented yet.")

+ 20 - 0
plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py

@@ -0,0 +1,20 @@
+# Copyright (c) 2015 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+##  Creates a new profile instance by parsing a serialised profile in version 1
+#   of the file format.
+#
+#   \param serialised The serialised form of a profile in version 1.
+#   \return A profile instance, or None if the file format is incorrect.
+def importVersion1(serialised):
+    return None #Not implemented yet.
+
+##  A representation of a profile used as intermediary form for conversion from
+#   one format to the other.
+class Profile:
+    ##  Serialises this profile as file format version 2.
+    #
+    #   \return A serialised form of this profile, serialised in version 2 of
+    #   the file format.
+    def exportVersion2():
+        raise Exception("Not implemented yet.")

+ 45 - 0
plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py

@@ -0,0 +1,45 @@
+# Copyright (c) 2015 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+from UM.VersionUpgrade import VersionUpgrade #Superclass of the plugin.
+
+from . import MachineInstance #To upgrade machine instances.
+from . import Preferences #To upgrade preferences.
+from . import Profile #To upgrade profiles.
+
+##  Converts configuration from Cura 2.1's file formats to Cura 2.2's.
+#
+#   It converts the machine instances, preferences and profiles.
+class VersionUpgrade21to22(VersionUpgrade):
+    ##  Converts machine instances from format version 1 to version 2.
+    #
+    #   \param serialised The serialised machine instance in version 1.
+    #   \return The serialised machine instance in version 2, or None if the
+    #   input was not of the correct format.
+    def upgradeMachineInstance(self, serialised):
+        machine_instance = MachineInstance.importVersion1(serialised)
+        if not machine_instance: #Invalid file format.
+            return None
+        return machine_instance.exportVersion2()
+
+    ##  Converts preferences from format version 2 to version 3.
+    #
+    #   \param serialised The serialised preferences file in version 2.
+    #   \return The serialised preferences file in version 3, or None if the
+    #   input was not of the correct format.
+    def upgradePreferences(self, serialised):
+        preferences = Preferences.importVersion2(serialised)
+        if not preferences: #Invalid file format.
+            return None
+        return preferences.exportVersion3()
+
+    ##  Converts profiles from format version 1 to version 2.
+    #
+    #   \param serialised The serialised profile in version 1.
+    #   \return The serialised profile in version 2, or None if the input was
+    #   not of the correct format.
+    def upgradeProfile(self, serialised):
+        profile = Profile.importVersion1(serialised)
+        if not profile: #Invalid file format.
+            return None
+        return profile.exportVersion2()

+ 35 - 0
plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py

@@ -0,0 +1,35 @@
+# Copyright (c) 2015 Ultimaker B.V.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+from . import VersionUpgrade21to22
+
+from UM.i18n import i18nCatalog
+catalog = i18nCatalog("cura")
+
+def getMetaData():
+    return {
+        "plugin": {
+            "name": catalog.i18nc("@label", "Version Upgrade 2.1 to 2.2"),
+            "author": "Ultimaker",
+            "version": "1.0",
+            "description": catalog.i18nc("@info:whatsthis", "Upgrades configurations from Cura 2.1 to Cura 2.2."),
+            "api": 2
+        },
+        "version_upgrade": {
+            "profile": {
+                "from": 1,
+                "to": 2
+            },
+            "preferences": {
+                "from": 2,
+                "to": 3
+            },
+            "machine_instance": {
+                "from": 1,
+                "to": 2
+            }
+        }
+    }
+
+def register(app):
+    return { "version_upgrade": VersionUpgrade21to22.VersionUpgrade21to22() }