diff options
Diffstat (limited to 'plugins/LegacyProfileReader/LegacyProfileReader.py')
-rw-r--r-- | plugins/LegacyProfileReader/LegacyProfileReader.py | 77 |
1 files changed, 43 insertions, 34 deletions
diff --git a/plugins/LegacyProfileReader/LegacyProfileReader.py b/plugins/LegacyProfileReader/LegacyProfileReader.py index 87b26eb4ec..0bc82ad287 100644 --- a/plugins/LegacyProfileReader/LegacyProfileReader.py +++ b/plugins/LegacyProfileReader/LegacyProfileReader.py @@ -16,58 +16,67 @@ from UM.Settings.InstanceContainer import InstanceContainer # The new profile t from cura.ReaderWriters.ProfileReader import ProfileReader # The plug-in type to implement. -## A plugin that reads profile data from legacy Cura versions. -# -# It reads a profile from an .ini file, and performs some translations on it. -# Not all translations are correct, mind you, but it is a best effort. class LegacyProfileReader(ProfileReader): - ## Initialises the legacy profile reader. - # - # This does nothing since the only other function is basically stateless. + """A plugin that reads profile data from legacy Cura versions. + + It reads a profile from an .ini file, and performs some translations on it. + Not all translations are correct, mind you, but it is a best effort. + """ + def __init__(self): + """Initialises the legacy profile reader. + + This does nothing since the only other function is basically stateless. + """ + super().__init__() - ## Prepares the default values of all legacy settings. - # - # These are loaded from the Dictionary of Doom. - # - # \param json The JSON file to load the default setting values from. This - # should not be a URL but a pre-loaded JSON handle. - # \return A dictionary of the default values of the legacy Cura version. def prepareDefaults(self, json: Dict[str, Dict[str, str]]) -> Dict[str, str]: + """Prepares the default values of all legacy settings. + + These are loaded from the Dictionary of Doom. + + :param json: The JSON file to load the default setting values from. This + should not be a URL but a pre-loaded JSON handle. + :return: A dictionary of the default values of the legacy Cura version. + """ + defaults = {} if "defaults" in json: for key in json["defaults"]: # We have to copy over all defaults from the JSON handle to a normal dict. defaults[key] = json["defaults"][key] return defaults - ## Prepares the local variables that can be used in evaluation of computing - # new setting values from the old ones. - # - # This fills a dictionary with all settings from the legacy Cura version - # and their values, so that they can be used in evaluating the new setting - # values as Python code. - # - # \param config_parser The ConfigParser that finds the settings in the - # legacy profile. - # \param config_section The section in the profile where the settings - # should be found. - # \param defaults The default values for all settings in the legacy Cura. - # \return A set of local variables, one for each setting in the legacy - # profile. def prepareLocals(self, config_parser, config_section, defaults): + """Prepares the local variables that can be used in evaluation of computing + + new setting values from the old ones. + + This fills a dictionary with all settings from the legacy Cura version + and their values, so that they can be used in evaluating the new setting + values as Python code. + + :param config_parser: The ConfigParser that finds the settings in the + legacy profile. + :param config_section: The section in the profile where the settings + should be found. + :param defaults: The default values for all settings in the legacy Cura. + :return: A set of local variables, one for each setting in the legacy + profile. + """ copied_locals = defaults.copy() # Don't edit the original! for option in config_parser.options(config_section): copied_locals[option] = config_parser.get(config_section, option) return copied_locals - ## Reads a legacy Cura profile from a file and returns it. - # - # \param file_name The file to read the legacy Cura profile from. - # \return The legacy 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 returned. def read(self, file_name): + """Reads a legacy Cura profile from a file and returns it. + + :param file_name: The file to read the legacy Cura profile from. + :return: The legacy Cura profile that was in the file, if any. If the + file could not be read or didn't contain a valid profile, None is returned. + """ + if file_name.split(".")[-1] != "ini": return None global_container_stack = Application.getInstance().getGlobalContainerStack() |