mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-08-06 13:34:01 -06:00
Add version upgrade that adds empty intent profile to the stacks
CURA-6534
This commit is contained in:
parent
a1bbb46555
commit
7cc4ac741c
6 changed files with 114 additions and 0 deletions
|
@ -0,0 +1,42 @@
|
|||
## Upgrades configurations from the state they were in at version 4.1 to the
|
||||
# state they should be in at version 4.2.
|
||||
import configparser
|
||||
import io
|
||||
from typing import Tuple, List
|
||||
|
||||
from UM.VersionUpgrade import VersionUpgrade
|
||||
|
||||
|
||||
class VersionUpgrade41to42(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 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)
|
||||
|
||||
# We should only have 6 levels when we start.
|
||||
assert "7" not in parser["containers"]
|
||||
|
||||
# Update version number.
|
||||
parser["general"]["version"] = "5"
|
||||
|
||||
# We added the intent container in Cura 4.2. 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()]
|
||||
|
34
plugins/VersionUpgrade/VersionUpgrade41to42/__init__.py
Normal file
34
plugins/VersionUpgrade/VersionUpgrade41to42/__init__.py
Normal file
|
@ -0,0 +1,34 @@
|
|||
# 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 VersionUpgrade41to42
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from UM.Application import Application
|
||||
|
||||
upgrade = VersionUpgrade41to42.VersionUpgrade41to42()
|
||||
|
||||
def getMetaData() -> Dict[str, Any]:
|
||||
return {
|
||||
"version_upgrade": {
|
||||
# From To Upgrade function
|
||||
("machine_stack", 4000007): ("machine_stack", 5000007, upgrade.upgradeStack),
|
||||
("extruder_train", 4000007): ("extruder_train", 5000007, upgrade.upgradeStack)
|
||||
},
|
||||
"sources": {
|
||||
"machine_stack": {
|
||||
"get_version": upgrade.getCfgVersion,
|
||||
"location": {"./machine_instances"}
|
||||
},
|
||||
"extruder_train": {
|
||||
"get_version": upgrade.getCfgVersion,
|
||||
"location": {"./extruders"}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def register(app: "Application") -> Dict[str, Any]:
|
||||
return {"version_upgrade": upgrade}
|
8
plugins/VersionUpgrade/VersionUpgrade41to42/plugin.json
Normal file
8
plugins/VersionUpgrade/VersionUpgrade41to42/plugin.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "Version Upgrade 4.1 to 4.2",
|
||||
"author": "Ultimaker B.V.",
|
||||
"version": "1.0.0",
|
||||
"description": "Upgrades configurations from Cura 4.1 to Cura 4.2.",
|
||||
"api": "6.0",
|
||||
"i18n-catalog": "cura"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue