mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Add version upgrade for Cura 4.12
Yep, there's gonna be a 4.12. Contributes to issue CURA-8510.
This commit is contained in:
parent
c5ca4850f1
commit
7521e174b0
3 changed files with 158 additions and 0 deletions
|
@ -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()]
|
56
plugins/VersionUpgrade/VersionUpgrade411to412/__init__.py
Normal file
56
plugins/VersionUpgrade/VersionUpgrade411to412/__init__.py
Normal file
|
@ -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}
|
|
@ -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"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue