mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 03:07:53 -06:00
94 lines
3.5 KiB
Python
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"] = "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()]
|