Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGhostkeeper <rubend@tutanota.com>2019-06-18 12:48:57 +0300
committerGhostkeeper <rubend@tutanota.com>2019-06-18 13:00:22 +0300
commit7fbdccffdbe99fdedb69197d1bb0170eecdc467a (patch)
treef654b17fc461deede4dc1cfb29d6aca761ad38fc /plugins/CuraProfileReader
parent6a650455870916754d76a6a81f597d35a6cbeb54 (diff)
Add typing
Diffstat (limited to 'plugins/CuraProfileReader')
-rw-r--r--plugins/CuraProfileReader/CuraProfileReader.py47
1 files changed, 25 insertions, 22 deletions
diff --git a/plugins/CuraProfileReader/CuraProfileReader.py b/plugins/CuraProfileReader/CuraProfileReader.py
index 11e58dac6d..911faf2366 100644
--- a/plugins/CuraProfileReader/CuraProfileReader.py
+++ b/plugins/CuraProfileReader/CuraProfileReader.py
@@ -1,6 +1,8 @@
-# Copyright (c) 2018 Ultimaker B.V.
+# Copyright (c) 2019 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
+
import configparser
+from typing import List, Optional, Tuple
from UM.PluginRegistry import PluginRegistry
from UM.Logger import Logger
@@ -17,19 +19,19 @@ import zipfile
class CuraProfileReader(ProfileReader):
## Initialises the cura profile reader.
# This does nothing since the only other function is basically stateless.
- def __init__(self):
+ def __init__(self) -> None:
super().__init__()
## Reads a cura profile from a file and returns it.
#
# \param file_name The file to read the cura profile from.
- # \return The cura profile that was in the file, if any. If the file could
- # not be read or didn't contain a valid profile, \code None \endcode is
+ # \return The cura profiles that were in the file, if any. If the file
+ # could not be read or didn't contain a valid profile, ``None`` is
# returned.
- def read(self, file_name):
+ def read(self, file_name: str) -> List[Optional[InstanceContainer]]:
try:
with zipfile.ZipFile(file_name, "r") as archive:
- results = []
+ results = [] #type: List[Optional[InstanceContainer]]
for profile_id in archive.namelist():
with archive.open(profile_id) as f:
serialized = f.read()
@@ -41,15 +43,16 @@ class CuraProfileReader(ProfileReader):
except zipfile.BadZipFile:
# It must be an older profile from Cura 2.1.
with open(file_name, encoding = "utf-8") as fhandle:
- serialized = fhandle.read()
- return [self._loadProfile(serialized, profile_id) for serialized, profile_id in self._upgradeProfile(serialized, file_name)]
+ serialized_bytes = fhandle.read()
+ return [self._loadProfile(serialized, profile_id) for serialized, profile_id in self._upgradeProfile(serialized_bytes, file_name)]
## Convert a profile from an old Cura to this Cura if needed.
#
- # \param serialized \type{str} The profile data to convert in the serialized on-disk format.
- # \param profile_id \type{str} The name of the profile.
- # \return \type{List[Tuple[str,str]]} List of serialized profile strings and matching profile names.
- def _upgradeProfile(self, serialized, profile_id):
+ # \param serialized The profile data to convert in the serialized on-disk
+ # format.
+ # \param profile_id The name of the profile.
+ # \return List of serialized profile strings and matching profile names.
+ def _upgradeProfile(self, serialized: str, profile_id: str) -> List[Tuple[str, str]]:
parser = configparser.ConfigParser(interpolation = None)
parser.read_string(serialized)
@@ -69,10 +72,10 @@ class CuraProfileReader(ProfileReader):
## Load a profile from a serialized string.
#
- # \param serialized \type{str} The profile data to read.
- # \param profile_id \type{str} The name of the profile.
- # \return \type{InstanceContainer|None}
- def _loadProfile(self, serialized, profile_id):
+ # \param serialized The profile data to read.
+ # \param profile_id The name of the profile.
+ # \return The profile that was stored in the string.
+ def _loadProfile(self, serialized: str, profile_id: str) -> Optional[InstanceContainer]:
# Create an empty profile.
profile = InstanceContainer(profile_id)
profile.setMetaDataEntry("type", "quality_changes")
@@ -88,12 +91,12 @@ class CuraProfileReader(ProfileReader):
## Upgrade a serialized profile to the current profile format.
#
- # \param serialized \type{str} The profile data to convert.
- # \param profile_id \type{str} The name of the profile.
- # \param source_version \type{int} The profile version of 'serialized'.
- # \return \type{List[Tuple[str,str]]} List of serialized profile strings and matching profile names.
- def _upgradeProfileVersion(self, serialized, profile_id, source_version):
- converter_plugins = PluginRegistry.getInstance().getAllMetaData(filter={"version_upgrade": {} }, active_only=True)
+ # \param serialized The profile data to convert.
+ # \param profile_id The name of the profile.
+ # \param source_version The profile version of 'serialized'.
+ # \return List of serialized profile strings and matching profile names.
+ def _upgradeProfileVersion(self, serialized: str, profile_id: str, source_version: int) -> List[Tuple[str, str]]:
+ converter_plugins = PluginRegistry.getInstance().getAllMetaData(filter = {"version_upgrade": {} }, active_only = True)
source_format = ("profile", source_version)
profile_convert_funcs = [plugin["version_upgrade"][source_format][2] for plugin in converter_plugins