mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-22 13:49:39 +08:00

The theme 'cura' was renamed to 'cura-light', so that needs to be updated in the user's preferences. Contributes to issue CURA-4148.
56 lines
2.3 KiB
Python
56 lines
2.3 KiB
Python
# Copyright (c) 2017 Ultimaker B.V.
|
|
# Cura is released under the terms of the AGPLv3 or higher.
|
|
|
|
import configparser #To parse preference files.
|
|
import io #To serialise the preference files afterwards.
|
|
|
|
from UM.VersionUpgrade import VersionUpgrade #We're inheriting from this.
|
|
|
|
_renamed_themes = {
|
|
"cura": "cura-light"
|
|
}
|
|
|
|
class VersionUpgrade27to30(VersionUpgrade):
|
|
## Gets the version number from a CFG file in Uranium's 2.7 format.
|
|
#
|
|
# Since the format may change, this is implemented for the 2.7 format only
|
|
# and needs to be included in the version upgrade system rather than
|
|
# globally in Uranium.
|
|
#
|
|
# \param serialised The serialised form of a CFG file.
|
|
# \return The version number stored in the CFG file.
|
|
# \raises ValueError The format of the version number in the file is
|
|
# incorrect.
|
|
# \raises KeyError The format of the file is incorrect.
|
|
def getCfgVersion(self, serialised):
|
|
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 a preferences file from version 2.7 to 3.0.
|
|
#
|
|
# \param serialised The serialised form of a preferences file.
|
|
# \param filename The name of the file to upgrade.
|
|
def upgradePreferences(self, serialised, filename):
|
|
parser = configparser.ConfigParser(interpolation=None)
|
|
parser.read_string(serialised)
|
|
|
|
# Update version numbers
|
|
if "general" not in parser:
|
|
parser["general"] = {}
|
|
parser["general"]["version"] = "5"
|
|
if "metadata" not in parser:
|
|
parser["metadata"] = {}
|
|
parser["metadata"]["setting_version"] = "2"
|
|
|
|
#Renamed themes.
|
|
if "theme" in parser["general"]:
|
|
if parser["general"]["theme"] in _renamed_themes:
|
|
parser["general"]["theme"] = _renamed_themes[parser["general"]["theme"]]
|
|
|
|
# Re-serialise the file.
|
|
output = io.StringIO()
|
|
parser.write(output)
|
|
return [filename], [output.getvalue()] |