mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
70 lines
2.9 KiB
Python
70 lines
2.9 KiB
Python
import configparser
|
|
from typing import Tuple, List
|
|
import io
|
|
from UM.VersionUpgrade import VersionUpgrade
|
|
|
|
|
|
class VersionUpgrade43to44(VersionUpgrade):
|
|
def getCfgVersion(self, serialised: str) -> int:
|
|
parser = configparser.ConfigParser(interpolation = None)
|
|
parser.read_string(serialised)
|
|
format_version = int(parser.get("general", "version")) # Explicitly give an exception when this fails. That means that the file format is not recognised.
|
|
setting_version = int(parser.get("metadata", "setting_version", fallback = "0"))
|
|
return format_version * 1000000 + setting_version
|
|
|
|
## Upgrades Preferences to have the new version number.
|
|
#
|
|
# This renames the renamed settings in the list of visible settings.
|
|
def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
|
|
parser = configparser.ConfigParser(interpolation = None)
|
|
parser.read_string(serialized)
|
|
|
|
# Update version number.
|
|
parser["metadata"]["setting_version"] = "10"
|
|
|
|
result = io.StringIO()
|
|
parser.write(result)
|
|
return [filename], [result.getvalue()]
|
|
|
|
## Upgrades instance containers to have the new version
|
|
# number.
|
|
#
|
|
# This renames the renamed settings in the containers.
|
|
def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
|
|
parser = configparser.ConfigParser(interpolation=None)
|
|
parser.read_string(serialized)
|
|
|
|
# Update version number.
|
|
parser["metadata"]["setting_version"] = "10"
|
|
|
|
# Intent profiles were added, so the quality changes should match with no intent (so "default")
|
|
if parser["metadata"].get("type", "") == "quality_changes":
|
|
parser["metadata"]["intent_category"] = "default"
|
|
|
|
result = io.StringIO()
|
|
parser.write(result)
|
|
return [filename], [result.getvalue()]
|
|
|
|
## Upgrades stacks to have the new version number.
|
|
def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
|
|
parser = configparser.ConfigParser(interpolation=None)
|
|
parser.read_string(serialized)
|
|
|
|
# Update version number.
|
|
parser["metadata"]["setting_version"] = "10"
|
|
|
|
# We should only have 6 levels when we start.
|
|
if "7" in parser["containers"]:
|
|
return ([], [])
|
|
|
|
# We added the intent container in Cura 4.4. This means that all other containers move one step down.
|
|
parser["containers"]["7"] = parser["containers"]["6"]
|
|
parser["containers"]["6"] = parser["containers"]["5"]
|
|
parser["containers"]["5"] = parser["containers"]["4"]
|
|
parser["containers"]["4"] = parser["containers"]["3"]
|
|
parser["containers"]["3"] = parser["containers"]["2"]
|
|
parser["containers"]["2"] = "empty_intent"
|
|
|
|
result = io.StringIO()
|
|
parser.write(result)
|
|
return [filename], [result.getvalue()]
|