diff options
author | Ghostkeeper <rubend@tutanota.com> | 2018-11-14 15:41:23 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2018-11-14 15:41:23 +0300 |
commit | ae2b3124721c9c74730073d178c0ac1927819b1c (patch) | |
tree | 9587731e71adb92bd9d8cb06b1ed93dbc5ce82a8 /plugins/VersionUpgrade/VersionUpgrade25to26 | |
parent | fe66d15b9e1b615ac894daddf24e1a1aeecb2408 (diff) |
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.
Diffstat (limited to 'plugins/VersionUpgrade/VersionUpgrade25to26')
-rw-r--r-- | plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py | 26 | ||||
-rw-r--r-- | plugins/VersionUpgrade/VersionUpgrade25to26/__init__.py | 11 |
2 files changed, 21 insertions, 16 deletions
diff --git a/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py b/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py index 6643edb765..5c9b94cca3 100644 --- a/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py +++ b/plugins/VersionUpgrade/VersionUpgrade25to26/VersionUpgrade25to26.py @@ -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" diff --git a/plugins/VersionUpgrade/VersionUpgrade25to26/__init__.py b/plugins/VersionUpgrade/VersionUpgrade25to26/__init__.py index 67aa73233f..c74b3218b6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade25to26/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade25to26/__init__.py @@ -1,11 +1,16 @@ -# Copyright (c) 2017 Ultimaker B.V. +# Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +from typing import Any, Dict, TYPE_CHECKING + from . import VersionUpgrade25to26 +if TYPE_CHECKING: + from UM.Application import Application + upgrade = VersionUpgrade25to26.VersionUpgrade25to26() -def getMetaData(): +def getMetaData() -> Dict[str, Any]: return { "version_upgrade": { # From To Upgrade function @@ -41,5 +46,5 @@ def getMetaData(): } } -def register(app): +def register(app: "Application") -> Dict[str, Any]: return { "version_upgrade": upgrade } |