mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Add version upgrader
CURA-10953
This commit is contained in:
parent
e899b9987c
commit
0141b750f5
3 changed files with 118 additions and 0 deletions
|
@ -0,0 +1,75 @@
|
|||
# Copyright (c) 2023 UltiMaker
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import configparser
|
||||
from typing import Tuple, List
|
||||
import io
|
||||
from UM.VersionUpgrade import VersionUpgrade
|
||||
import re
|
||||
|
||||
|
||||
|
||||
class VersionUpgrade54to55(VersionUpgrade):
|
||||
profile_regex = re.compile(
|
||||
r"um\_(?P<machine>s(3|5|7))_(?P<core_type>aa|cc|bb)(?P<nozzle_size>0\.(6|4|8))_(?P<material>pla|petg|abs)_(?P<layer_height>0\.\d{1,2}mm)")
|
||||
|
||||
@staticmethod
|
||||
def _isUpgradedUltimakerDefinitionId(definition_id: str) -> bool:
|
||||
if definition_id.startswith("ultimaker_s5"):
|
||||
return True
|
||||
if definition_id.startswith("ultimaker_s3"):
|
||||
return True
|
||||
if definition_id.startswith("ultimaker_s7"):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def _isBrandedMaterialID(material_id):
|
||||
return material_id.startswith("ultimaker_")
|
||||
|
||||
|
||||
|
||||
@staticmethod
|
||||
def upgradeStack(serialized: str, filename: str) -> Tuple[List[str], List[str]]:
|
||||
"""
|
||||
Upgrades stacks to have the new version number.
|
||||
|
||||
: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 "general" not in parser:
|
||||
parser["general"] = {}
|
||||
|
||||
extruder_definition_id = parser["containers"]["7"]
|
||||
if parser["metadata"]["type"] == "extruder_train" and VersionUpgrade54to55._isUpgradedUltimakerDefinitionId(extruder_definition_id):
|
||||
# We only need to update certain Ultimaker extruder ID's
|
||||
material_id = parser["containers"]["4"]
|
||||
quality_id = parser["containers"]["3"]
|
||||
intent_id = parser["containers"]["2"]
|
||||
if VersionUpgrade54to55._isBrandedMaterialID(material_id):
|
||||
# We have an Ultimaker branded material ID, so we should change the intent & quality!
|
||||
|
||||
quality_id = VersionUpgrade54to55.profile_regex.sub(
|
||||
"um_\g<machine>_\g<core_type>\g<nozzle_size>_um-\g<material>_\g<layer_height>", quality_id)
|
||||
|
||||
|
||||
intent_id = VersionUpgrade54to55.profile_regex.sub(
|
||||
"um_\g<machine>_\g<core_type>\g<nozzle_size>_um-\g<material>_\g<layer_height>", intent_id)
|
||||
|
||||
|
||||
parser["containers"]["3"] = quality_id
|
||||
parser["containers"]["2"] = intent_id
|
||||
|
||||
# We're not changing any settings, but we are changing how certain stacks are handled.
|
||||
parser["general"]["version"] = "6"
|
||||
|
||||
result = io.StringIO()
|
||||
parser.write(result)
|
||||
return [filename], [result.getvalue()]
|
35
plugins/VersionUpgrade/VersionUpgrade54to55/__init__.py
Normal file
35
plugins/VersionUpgrade/VersionUpgrade54to55/__init__.py
Normal file
|
@ -0,0 +1,35 @@
|
|||
# Copyright (c) 2023 UltiMaker
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from typing import Any, Dict, TYPE_CHECKING
|
||||
|
||||
from . import VersionUpgrade54to55
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from UM.Application import Application
|
||||
|
||||
upgrade = VersionUpgrade54to55.VersionUpgrade54to55()
|
||||
|
||||
|
||||
def getMetaData() -> Dict[str, Any]:
|
||||
return {
|
||||
"version_upgrade": {
|
||||
# From To Upgrade function
|
||||
("machine_stack", 5000022): ("machine_stack", 6000022, upgrade.upgradeStack),
|
||||
("extruder_train", 5000022): ("extruder_train", 6000022, 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/VersionUpgrade54to55/plugin.json
Normal file
8
plugins/VersionUpgrade/VersionUpgrade54to55/plugin.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"name": "Version Upgrade 5.3 to 5.4",
|
||||
"author": "UltiMaker",
|
||||
"version": "1.0.0",
|
||||
"description": "Upgrades configurations from Cura 5.4 to Cura 5.5.",
|
||||
"api": 8,
|
||||
"i18n-catalog": "cura"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue