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:
authorGhostkeeper <rubend@tutanota.com>2021-09-14 17:23:38 +0300
committerGhostkeeper <rubend@tutanota.com>2021-09-14 17:23:38 +0300
commit7521e174b0381a0a44e7779c49388cc5db90792c (patch)
tree8bbb071b4f8129e7084b23aa4204de6f4a9f053e /plugins/VersionUpgrade
parentc5ca4850f178266dfcafed8cbf18704009b0d34c (diff)
Add version upgrade for Cura 4.12
Yep, there's gonna be a 4.12. Contributes to issue CURA-8510.
Diffstat (limited to 'plugins/VersionUpgrade')
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade411to412/VersionUpgrade411to412.py94
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade411to412/__init__.py56
-rw-r--r--plugins/VersionUpgrade/VersionUpgrade411to412/plugin.json8
3 files changed, 158 insertions, 0 deletions
diff --git a/plugins/VersionUpgrade/VersionUpgrade411to412/VersionUpgrade411to412.py b/plugins/VersionUpgrade/VersionUpgrade411to412/VersionUpgrade411to412.py
new file mode 100644
index 0000000000..9e57db5b7a
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade411to412/VersionUpgrade411to412.py
@@ -0,0 +1,94 @@
+# Copyright (c) 2021 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+import configparser
+import io
+from typing import List, Tuple
+
+from UM.VersionUpgrade import VersionUpgrade
+
+
+class VersionUpgrade411to412(VersionUpgrade):
+ """
+ Upgrades configurations from the state they were in at version 4.11 to the
+ state they should be in at version 4.12.
+ """
+
+ _flsun_profile_mapping = {
+ "extra_coarse": "flsun_sr_normal",
+ "coarse": "flsun_sr_normal",
+ "extra_fast": "flsun_sr_normal",
+ "draft": "flsun_sr_normal",
+ "fast": "flsun_sr_normal",
+ "normal": "flsun_sr_normal",
+ "high": "flsun_sr_fine"
+ }
+
+ def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
+ """
+ Upgrades preferences to have the new version number.
+ :param serialized: The original contents of the preferences file.
+ :param filename: The file name of the preferences file.
+ :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.
+ parser["metadata"]["setting_version"] = "18"
+
+ result = io.StringIO()
+ parser.write(result)
+ return [filename], [result.getvalue()]
+
+
+ def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
+ """
+ Upgrades instance containers to have the new version number.
+ :param serialized: The original contents of the instance container.
+ :param filename: The file name of the instance container.
+ :return: A list of file names, and a list of the new contents for those
+ files.
+ """
+ parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ())
+ parser.read_string(serialized)
+
+ # Update setting version number.
+ if "metadata" not in parser:
+ parser["metadata"] = {}
+ parser["metadata"]["setting_version"] = "18"
+
+ result = io.StringIO()
+ parser.write(result)
+ return [filename], [result.getvalue()]
+
+ def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
+ """
+ Upgrades container stacks to have the new version number.
+ Upgrades container stacks for FLSun Racer to change their profiles.
+ :param serialized: The original contents of the container stack.
+ :param filename: The file name of the container stack.
+ :return: A list of file names, and a list of the new contents for those
+ files.
+ """
+ parser = configparser.ConfigParser(interpolation = None)
+ parser.read_string(serialized)
+
+ # Update setting version number.
+ if "metadata" not in parser:
+ parser["metadata"] = {}
+ parser["metadata"]["setting_version"] = "18"
+
+ # Change renamed profiles.
+ if "containers" in parser:
+ definition_id = parser["containers"].get("7")
+ if definition_id == "flsun_sr":
+ if parser["metadata"].get("type", "machine") == "machine": # Only global stacks.
+ old_quality = parser["containers"].get("3")
+ new_quality = self._flsun_profile_mapping.get(old_quality, "flsun_sr_normal")
+ parser["containers"]["3"] = new_quality
+
+ result = io.StringIO()
+ parser.write(result)
+ return [filename], [result.getvalue()]
diff --git a/plugins/VersionUpgrade/VersionUpgrade411to412/__init__.py b/plugins/VersionUpgrade/VersionUpgrade411to412/__init__.py
new file mode 100644
index 0000000000..ec95d3da90
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade411to412/__init__.py
@@ -0,0 +1,56 @@
+# Copyright (c) 2021 Ultimaker B.V.
+# Cura is released under the terms of the LGPLv3 or higher.
+
+from typing import Any, Dict, TYPE_CHECKING
+
+from . import VersionUpgrade411to412
+
+if TYPE_CHECKING:
+ from UM.Application import Application
+
+upgrade = VersionUpgrade411to412.VersionUpgrade411to412()
+
+
+def getMetaData() -> Dict[str, Any]:
+ return {
+ "version_upgrade": {
+ # From To Upgrade function
+ ("machine_stack", 5000017): ("machine_stack", 5000018, upgrade.upgradeStack),
+ ("extruder_train", 5000017): ("extruder_train", 5000018, upgrade.upgradeStack),
+ ("definition_changes", 4000017): ("definition_changes", 4000018, upgrade.upgradeInstanceContainer),
+ ("quality_changes", 4000017): ("quality_changes", 4000018, upgrade.upgradeInstanceContainer),
+ ("quality", 4000017): ("quality", 4000018, upgrade.upgradeInstanceContainer),
+ ("user", 4000017): ("user", 4000018, upgrade.upgradeInstanceContainer),
+ ("preferences", 7000017): ("preferences", 7000018, upgrade.upgradePreferences),
+ },
+ "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}
diff --git a/plugins/VersionUpgrade/VersionUpgrade411to412/plugin.json b/plugins/VersionUpgrade/VersionUpgrade411to412/plugin.json
new file mode 100644
index 0000000000..4ac4f264c8
--- /dev/null
+++ b/plugins/VersionUpgrade/VersionUpgrade411to412/plugin.json
@@ -0,0 +1,8 @@
+{
+ "name": "Version Upgrade 4.11 to 4.12",
+ "author": "Ultimaker B.V.",
+ "version": "1.0.0",
+ "description": "Upgrades configurations from Cura 4.11 to Cura 4.12.",
+ "api": 7,
+ "i18n-catalog": "cura"
+}