Revert "Removed the upgrader for the machine and extruder stack"

This reverts commit 4707560d
This commit is contained in:
jelle Spijker 2021-04-02 14:45:16 +02:00 committed by Jelle Spijker
parent 72478994ec
commit ebc4f45da6
No known key found for this signature in database
GPG key ID: 6662DC033BE6B99A
2 changed files with 56 additions and 1 deletions

View file

@ -36,6 +36,51 @@ class VersionUpgrade48to49(VersionUpgrade):
parser.write(result) parser.write(result)
return [filename], [result.getvalue()] return [filename], [result.getvalue()]
def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
"""
Upgrades stacks to have the new version number.
This updates the post-processing scripts with new parameters.
:param serialized: The original contents of the stack.
:param filename: The original file name of the stack.
: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.
if "metadata" not in parser:
parser["metadata"] = {}
parser["metadata"]["setting_version"] = "17"
# Update Display Progress on LCD script parameters if present.
if "post_processing_scripts" in parser["metadata"]:
new_scripts_entries = []
for script_str in parser["metadata"]["post_processing_scripts"].split("\n"):
if not script_str:
continue
script_str = script_str.replace(r"\\\n", "\n").replace(r"\\\\", "\\\\") # Unescape escape sequences.
script_parser = configparser.ConfigParser(interpolation=None)
script_parser.optionxform = str # type: ignore # Don't transform the setting keys as they are case-sensitive.
script_parser.read_string(script_str)
# Update Display Progress on LCD parameters.
script_id = script_parser.sections()[0]
if script_id == "DisplayProgressOnLCD":
script_parser[script_id]["time_remaining"] = "m117" if script_parser[script_id]["time_remaining"] == "True" else "none"
script_io = io.StringIO()
script_parser.write(script_io)
script_str = script_io.getvalue()
script_str = script_str.replace("\\\\", r"\\\\").replace("\n", r"\\\n") # Escape newlines because configparser sees those as section delimiters.
new_scripts_entries.append(script_str)
parser["metadata"]["post_processing_scripts"] = "\n".join(new_scripts_entries)
result = io.StringIO()
parser.write(result)
return [filename], [result.getvalue()]
def upgradeSettingVisibility(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]: def upgradeSettingVisibility(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
""" """
Upgrades setting visibility to have a version number and move moved settings to a different category Upgrades setting visibility to have a version number and move moved settings to a different category

View file

@ -15,13 +15,23 @@ def getMetaData() -> Dict[str, Any]:
"version_upgrade": { "version_upgrade": {
# From To Upgrade function # From To Upgrade function
("preferences", 6000016): ("preferences", 7000016, upgrade.upgradePreferences), ("preferences", 6000016): ("preferences", 7000016, upgrade.upgradePreferences),
("setting_visibility", 1000000): ("setting_visibility", 2000017, upgrade.upgradeSettingVisibility), ("machine_stack", 4000016): ("machine_stack", 5000016, upgrade.upgradeStack),
("extruder_train", 4000016): ("extruder_train", 5000016, upgrade.upgradeStack),
("setting_visibility", 1000000): ("setting_visibility", 2000016, upgrade.upgradeSettingVisibility),
}, },
"sources": { "sources": {
"preferences": { "preferences": {
"get_version": upgrade.getCfgVersion, "get_version": upgrade.getCfgVersion,
"location": {"."} "location": {"."}
}, },
"machine_stack": {
"get_version": upgrade.getCfgVersion,
"location": {"./machine_instances"}
},
"extruder_train": {
"get_version": upgrade.getCfgVersion,
"location": {"./extruders"}
},
"setting_visibility": { "setting_visibility": {
"get_version": upgrade.getCfgVersion, "get_version": upgrade.getCfgVersion,
"location": {"./setting_visibility"} "location": {"./setting_visibility"}