Cura/plugins/VersionUpgrade/VersionUpgrade411to412/VersionUpgrade411to412.py
Konstantinos Karmas 3e143a012a Change the setting version to 19
Since the setting version 18 is used in the arachne beta build, we decided to make the the setting version to 19 in the normal releases, so that we make sure that projects made in arachne beta won't use any version upgrade scripts if a user attempts to open them in 4.12.

CURA-8510
2021-09-15 16:25:04 +02:00

94 lines
3.5 KiB
Python

# 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"] = "19"
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"] = "19"
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"] = "19"
# 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()]