mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 06:57:28 -06:00
Add typing for all version upgrade plug-ins
Hopefully we'll take this typing along when we next copy-paste the stuffs. Contributes to issue CURA-5936.
This commit is contained in:
parent
fe66d15b9e
commit
ae2b312472
21 changed files with 200 additions and 150 deletions
|
@ -4,6 +4,7 @@
|
|||
import configparser #To parse the files we need to upgrade and write the new files.
|
||||
import io #To serialise configparser output to a string.
|
||||
import os
|
||||
from typing import Dict, List, Set, Tuple
|
||||
from urllib.parse import quote_plus
|
||||
|
||||
from UM.Resources import Resources
|
||||
|
@ -12,19 +13,18 @@ from UM.VersionUpgrade import VersionUpgrade
|
|||
_removed_settings = { #Settings that were removed in 2.5.
|
||||
"start_layers_at_same_position",
|
||||
"sub_div_rad_mult"
|
||||
}
|
||||
} # type: Set[str]
|
||||
|
||||
_split_settings = { #These settings should be copied to all settings it was split into.
|
||||
"support_interface_line_distance": {"support_roof_line_distance", "support_bottom_line_distance"}
|
||||
}
|
||||
} # type: Dict[str, Set[str]]
|
||||
|
||||
## A collection of functions that convert the configuration of the user in Cura
|
||||
# 2.5 to a configuration for Cura 2.6.
|
||||
#
|
||||
# All of these methods are essentially stateless.
|
||||
class VersionUpgrade25to26(VersionUpgrade):
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
self._current_fdm_printer_count = 2
|
||||
|
||||
|
@ -39,7 +39,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
# \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):
|
||||
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.
|
||||
|
@ -50,7 +50,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
#
|
||||
# \param serialised The serialised form of a preferences file.
|
||||
# \param filename The name of the file to upgrade.
|
||||
def upgradePreferences(self, serialised, filename):
|
||||
def upgradePreferences(self, serialised: str, filename: str) -> Tuple[List[str], List[str]]:
|
||||
parser = configparser.ConfigParser(interpolation = None)
|
||||
parser.read_string(serialised)
|
||||
|
||||
|
@ -86,7 +86,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
#
|
||||
# \param serialised The serialised form of a quality profile.
|
||||
# \param filename The name of the file to upgrade.
|
||||
def upgradeInstanceContainer(self, serialised, filename):
|
||||
def upgradeInstanceContainer(self, serialised: str, filename: str) -> Tuple[List[str], List[str]]:
|
||||
parser = configparser.ConfigParser(interpolation = None)
|
||||
parser.read_string(serialised)
|
||||
|
||||
|
@ -116,7 +116,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
#
|
||||
# \param serialised The serialised form of a quality profile.
|
||||
# \param filename The name of the file to upgrade.
|
||||
def upgradeMachineStack(self, serialised, filename):
|
||||
def upgradeMachineStack(self, serialised: str, filename: str) -> Tuple[List[str], List[str]]:
|
||||
parser = configparser.ConfigParser(interpolation = None)
|
||||
parser.read_string(serialised)
|
||||
|
||||
|
@ -149,7 +149,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
return [filename], [output.getvalue()]
|
||||
|
||||
## Acquires the next unique extruder stack index number for the Custom FDM Printer.
|
||||
def _acquireNextUniqueCustomFdmPrinterExtruderStackIdIndex(self):
|
||||
def _acquireNextUniqueCustomFdmPrinterExtruderStackIdIndex(self) -> int:
|
||||
extruder_stack_dir = os.path.join(Resources.getDataStoragePath(), "extruders")
|
||||
file_name_list = os.listdir(extruder_stack_dir)
|
||||
file_name_list = [os.path.basename(file_name) for file_name in file_name_list]
|
||||
|
@ -169,7 +169,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
|
||||
return self._current_fdm_printer_count
|
||||
|
||||
def _checkCustomFdmPrinterHasExtruderStack(self, machine_id):
|
||||
def _checkCustomFdmPrinterHasExtruderStack(self, machine_id: str) -> bool:
|
||||
# go through all extruders and make sure that this custom FDM printer has extruder stacks.
|
||||
extruder_stack_dir = os.path.join(Resources.getDataStoragePath(), "extruders")
|
||||
has_extruders = False
|
||||
|
@ -197,7 +197,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
|
||||
return has_extruders
|
||||
|
||||
def _createCustomFdmPrinterExtruderStack(self, machine_id: str, position: int, quality_id: str, material_id: str):
|
||||
def _createCustomFdmPrinterExtruderStack(self, machine_id: str, position: int, quality_id: str, material_id: str) -> None:
|
||||
stack_id = "custom_extruder_%s" % (position + 1)
|
||||
if self._current_fdm_printer_count > 1:
|
||||
stack_id += " #%s" % self._current_fdm_printer_count
|
||||
|
@ -256,7 +256,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
|
||||
## Creates a definition changes container which doesn't contain anything for the Custom FDM Printers.
|
||||
# The container ID will be automatically generated according to the given stack name.
|
||||
def _getCustomFdmPrinterDefinitionChanges(self, stack_id: str):
|
||||
def _getCustomFdmPrinterDefinitionChanges(self, stack_id: str) -> configparser.ConfigParser:
|
||||
# In 2.5, there is no definition_changes container for the Custom FDM printer, so it should be safe to use the
|
||||
# default name unless some one names the printer as something like "Custom FDM Printer_settings".
|
||||
definition_changes_id = stack_id + "_settings"
|
||||
|
@ -277,7 +277,7 @@ class VersionUpgrade25to26(VersionUpgrade):
|
|||
|
||||
## Creates a user settings container which doesn't contain anything for the Custom FDM Printers.
|
||||
# The container ID will be automatically generated according to the given stack name.
|
||||
def _getCustomFdmPrinterUserSettings(self, stack_id: str):
|
||||
def _getCustomFdmPrinterUserSettings(self, stack_id: str) -> configparser.ConfigParser:
|
||||
# For the extruder stacks created in the upgrade, also create user_settings containers so the user changes
|
||||
# will be saved.
|
||||
user_settings_id = stack_id + "_user"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue