mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 19:09:01 +08:00
Version Upgrade 44 to 45
Includes test for changes made in CURA-6522 CURA-6522
This commit is contained in:
parent
e5c9bca3d0
commit
88b3a2506d
@ -0,0 +1,69 @@
|
|||||||
|
import configparser
|
||||||
|
from typing import Tuple, List
|
||||||
|
import io
|
||||||
|
from UM.VersionUpgrade import VersionUpgrade
|
||||||
|
|
||||||
|
# Merged preferences: machine_head_polygon and machine_head_with_fans_polygon -> machine_head_with_fans_polygon
|
||||||
|
# When both are present, machine_head_polygon will be removed
|
||||||
|
# When only one of the two is present, it's value will be used
|
||||||
|
|
||||||
|
|
||||||
|
class VersionUpgrade44to45(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"] = "11"
|
||||||
|
|
||||||
|
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"] = "11"
|
||||||
|
|
||||||
|
if "values" in parser:
|
||||||
|
# merge machine_head_with_fans_polygon (preferred) and machine_head_polygon
|
||||||
|
if "machine_head_with_fans_polygon" in parser["values"]:
|
||||||
|
if "machine_head_polygon" in parser["values"]:
|
||||||
|
del parser["values"]["machine_head_polygon"]
|
||||||
|
elif "machine_head_polygon" in parser["values"]:
|
||||||
|
parser["values"]["machine_head_with_fans_polygon"] = parser["values"]["machine_head_polygon"]
|
||||||
|
del parser["values"]["machine_head_polygon"]
|
||||||
|
|
||||||
|
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.
|
||||||
|
if "metadata" not in parser:
|
||||||
|
parser["metadata"] = {}
|
||||||
|
parser["metadata"]["setting_version"] = "11"
|
||||||
|
|
||||||
|
result = io.StringIO()
|
||||||
|
parser.write(result)
|
||||||
|
return [filename], [result.getvalue()]
|
61
plugins/VersionUpgrade/VersionUpgrade44to45/__init__.py
Normal file
61
plugins/VersionUpgrade/VersionUpgrade44to45/__init__.py
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from typing import Any, Dict, TYPE_CHECKING
|
||||||
|
|
||||||
|
from . import VersionUpgrade44to45
|
||||||
|
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from UM.Application import Application
|
||||||
|
|
||||||
|
upgrade = VersionUpgrade44to45.VersionUpgrade44to45()
|
||||||
|
|
||||||
|
|
||||||
|
def getMetaData() -> Dict[str, Any]:
|
||||||
|
return {
|
||||||
|
"version_upgrade": {
|
||||||
|
# From To Upgrade function
|
||||||
|
("preferences", 6000010): ("preferences", 6000011, upgrade.upgradePreferences),
|
||||||
|
("machine_stack", 4000010): ("machine_stack", 4000011, upgrade.upgradeStack),
|
||||||
|
("extruder_train", 4000010): ("extruder_train", 4000011, upgrade.upgradeStack),
|
||||||
|
("definition_changes", 4000010): ("definition_changes", 4000011, upgrade.upgradeInstanceContainer),
|
||||||
|
("quality_changes", 4000010): ("quality_changes", 4000011, upgrade.upgradeInstanceContainer),
|
||||||
|
("quality", 4000010): ("quality", 4000011, upgrade.upgradeInstanceContainer),
|
||||||
|
("user", 4000010): ("user", 4000011, upgrade.upgradeInstanceContainer),
|
||||||
|
},
|
||||||
|
"sources": {
|
||||||
|
"preferences": {
|
||||||
|
"get_version": upgrade.getCfgVersion,
|
||||||
|
"location": {"."}
|
||||||
|
},
|
||||||
|
"machine_stack": {
|
||||||
|
"get_version": upgrade.getCfgVersion,
|
||||||
|
"location": {"./machine_instances"}
|
||||||
|
},
|
||||||
|
"extruder_train": {
|
||||||
|
"get_version": upgrade.getCfgVersion,
|
||||||
|
"location": {"./extruders"}
|
||||||
|
},
|
||||||
|
"definition_changes": {
|
||||||
|
"get_version": upgrade.getCfgVersion,
|
||||||
|
"location": {"./definition_changes"}
|
||||||
|
},
|
||||||
|
"quality_changes": {
|
||||||
|
"get_version": upgrade.getCfgVersion,
|
||||||
|
"location": {"./quality_changes"}
|
||||||
|
},
|
||||||
|
"quality": {
|
||||||
|
"get_version": upgrade.getCfgVersion,
|
||||||
|
"location": {"./quality"}
|
||||||
|
},
|
||||||
|
"user": {
|
||||||
|
"get_version": upgrade.getCfgVersion,
|
||||||
|
"location": {"./user"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def register(app: "Application") -> Dict[str, Any]:
|
||||||
|
return {"version_upgrade": upgrade}
|
8
plugins/VersionUpgrade/VersionUpgrade44to45/plugin.json
Normal file
8
plugins/VersionUpgrade/VersionUpgrade44to45/plugin.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "Version Upgrade 4.4 to 4.5",
|
||||||
|
"author": "Ultimaker B.V.",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Upgrades configurations from Cura 4.4 to Cura 4.5.",
|
||||||
|
"api": "7.0",
|
||||||
|
"i18n-catalog": "cura"
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
import configparser
|
||||||
|
|
||||||
|
import VersionUpgrade44to45
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
before_update = """[general]
|
||||||
|
version = 4
|
||||||
|
name = Creality CR-10S_settings
|
||||||
|
definition = creality_cr10s
|
||||||
|
|
||||||
|
[metadata]
|
||||||
|
type = definition_changes
|
||||||
|
setting_version = 10
|
||||||
|
|
||||||
|
[values]
|
||||||
|
%s
|
||||||
|
"""
|
||||||
|
before_after_list = [
|
||||||
|
("machine_head_with_fans_polygon = [[-99, 99], [-99, -44], [45, 99], [45, -44]]", "[[-99, 99], [-99, -44], [45, 99], [45, -44]]"),
|
||||||
|
("", None),
|
||||||
|
("machine_head_polygon = [[-98, 99], [-99, -44], [45, 99], [45, -44]]", "[[-98, 99], [-99, -44], [45, 99], [45, -44]]"),
|
||||||
|
("machine_head_polygon = [[-87, 99], [-99, -44], [45, 99], [45, -44]]\nmachine_head_with_fans_polygon = [[-99, 99], [-99, -44], [45, 99], [45, -44]]", "[[-99, 99], [-99, -44], [45, 99], [45, -44]]"),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class TestVersionUpgrade44to45:
|
||||||
|
|
||||||
|
@pytest.mark.parametrize("after_string, after_value", before_after_list)
|
||||||
|
def test_upgrade(self, after_string, after_value):
|
||||||
|
upgrader = VersionUpgrade44to45.VersionUpgrade44to45()
|
||||||
|
|
||||||
|
|
||||||
|
file_name, new_data = upgrader.upgradeInstanceContainer(before_update % after_string, "whatever")
|
||||||
|
parser = configparser.ConfigParser(interpolation=None)
|
||||||
|
parser.read_string(new_data[0])
|
||||||
|
|
||||||
|
if after_value is None:
|
||||||
|
assert "machine_head_with_fans_polygon" not in parser["values"]
|
||||||
|
else:
|
||||||
|
assert parser["values"]["machine_head_with_fans_polygon"] == after_value
|
||||||
|
|
||||||
|
assert "machine_head_polygon" not in parser["values"]
|
Loading…
x
Reference in New Issue
Block a user