From 2f4e63a944281ef49da3212f60cafff70797ed6f Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 11:46:30 +0200 Subject: [PATCH 01/62] Add boilerplate version upgrade plug-in This plug-in does nothing at the moment. It merely says that it is able to upgrade configuration from version 2.1 to 2.2, but then raises exceptions when you actually try to use it. This is by design. I will now implement the functions that do the conversion. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 21 +++++++++ .../VersionUpgrade21to22/Preferences.py | 20 +++++++++ .../VersionUpgrade21to22/Profile.py | 20 +++++++++ .../VersionUpgrade21to22.py | 45 +++++++++++++++++++ .../VersionUpgrade21to22/__init__.py | 35 +++++++++++++++ 5 files changed, 141 insertions(+) create mode 100644 plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py create mode 100644 plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py create mode 100644 plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py create mode 100644 plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py create mode 100644 plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py new file mode 100644 index 0000000000..0fafe94218 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -0,0 +1,21 @@ +# Copyright (c) 2015 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +## Creates a new machine instance instance by parsing a serialised machine +# instance in version 1 of the file format. +# +# \param serialised The serialised form of a machine instance in version 1. +# \return A machine instance instance, or None if the file format is +# incorrect. +def importVersion1(serialised): + return None #Not implemented yet. + +## A representation of a machine instance used as intermediary form for +# conversion from one format to the other. +class MachineInstance: + ## Serialises this machine instance as file format version 2. + # + # \return A serialised form of this machine instance, serialised in + # version 2 of the file format. + def exportVersion2(): + raise Exception("Not implemented yet.") \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py new file mode 100644 index 0000000000..7027ce960f --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -0,0 +1,20 @@ +# Copyright (c) 2015 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +## Creates a new preferences instance by parsing a serialised preferences file +# in version 2 of the file format. +# +# \param serialised The serialised form of a preferences file in version 2. +# \return A preferences instance, or None if the file format is incorrect. +def importVersion2(serialised): + return None #Not implemented yet. + +## A representation of a preferences file used as intermediary form for +# conversion from one format to the other. +class Preferences: + ## Serialises this preferences file as file format version 3. + # + # \return A serialised form of this preferences file, serialised in + # version 3 of the file format. + def exportVersion3(): + raise Exception("Not implemented yet.") \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py new file mode 100644 index 0000000000..50d5b82b31 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -0,0 +1,20 @@ +# Copyright (c) 2015 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +## Creates a new profile instance by parsing a serialised profile in version 1 +# of the file format. +# +# \param serialised The serialised form of a profile in version 1. +# \return A profile instance, or None if the file format is incorrect. +def importVersion1(serialised): + return None #Not implemented yet. + +## A representation of a profile used as intermediary form for conversion from +# one format to the other. +class Profile: + ## Serialises this profile as file format version 2. + # + # \return A serialised form of this profile, serialised in version 2 of + # the file format. + def exportVersion2(): + raise Exception("Not implemented yet.") \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py new file mode 100644 index 0000000000..5a333c8f5b --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -0,0 +1,45 @@ +# Copyright (c) 2015 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +from UM.VersionUpgrade import VersionUpgrade #Superclass of the plugin. + +from . import MachineInstance #To upgrade machine instances. +from . import Preferences #To upgrade preferences. +from . import Profile #To upgrade profiles. + +## Converts configuration from Cura 2.1's file formats to Cura 2.2's. +# +# It converts the machine instances, preferences and profiles. +class VersionUpgrade21to22(VersionUpgrade): + ## Converts machine instances from format version 1 to version 2. + # + # \param serialised The serialised machine instance in version 1. + # \return The serialised machine instance in version 2, or None if the + # input was not of the correct format. + def upgradeMachineInstance(self, serialised): + machine_instance = MachineInstance.importVersion1(serialised) + if not machine_instance: #Invalid file format. + return None + return machine_instance.exportVersion2() + + ## Converts preferences from format version 2 to version 3. + # + # \param serialised The serialised preferences file in version 2. + # \return The serialised preferences file in version 3, or None if the + # input was not of the correct format. + def upgradePreferences(self, serialised): + preferences = Preferences.importVersion2(serialised) + if not preferences: #Invalid file format. + return None + return preferences.exportVersion3() + + ## Converts profiles from format version 1 to version 2. + # + # \param serialised The serialised profile in version 1. + # \return The serialised profile in version 2, or None if the input was + # not of the correct format. + def upgradeProfile(self, serialised): + profile = Profile.importVersion1(serialised) + if not profile: #Invalid file format. + return None + return profile.exportVersion2() \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py new file mode 100644 index 0000000000..76546d1dd2 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -0,0 +1,35 @@ +# Copyright (c) 2015 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +from . import VersionUpgrade21to22 + +from UM.i18n import i18nCatalog +catalog = i18nCatalog("cura") + +def getMetaData(): + return { + "plugin": { + "name": catalog.i18nc("@label", "Version Upgrade 2.1 to 2.2"), + "author": "Ultimaker", + "version": "1.0", + "description": catalog.i18nc("@info:whatsthis", "Upgrades configurations from Cura 2.1 to Cura 2.2."), + "api": 2 + }, + "version_upgrade": { + "profile": { + "from": 1, + "to": 2 + }, + "preferences": { + "from": 2, + "to": 3 + }, + "machine_instance": { + "from": 1, + "to": 2 + } + } + } + +def register(app): + return { "version_upgrade": VersionUpgrade21to22.VersionUpgrade21to22() } From b643fe8fd0c8643a359c98d40aa3d6d9b511c67f Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 13:44:16 +0200 Subject: [PATCH 02/62] Translucent translation of machine instances Machine instances are translucently translated from version 1 to version 2. No setting changes are applied yet, nor has the format itself changed. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 61 ++++++++++++++++++- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 0fafe94218..f924f4756d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -1,6 +1,11 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. +import UM.SettingsError #To indicate that a file is of incorrect format. + +import configparser #To read config files. +import io #To write config files to strings as if they were files. + ## Creates a new machine instance instance by parsing a serialised machine # instance in version 1 of the file format. # @@ -8,14 +13,66 @@ # \return A machine instance instance, or None if the file format is # incorrect. def importVersion1(serialised): - return None #Not implemented yet. + return MachineInstance(serialised) ## A representation of a machine instance used as intermediary form for # conversion from one format to the other. class MachineInstance: + ## Reads version 1 of the file format, storing it in memory. + # + # \param serialised A string with the contents of a machine instance file. + def __init__(self, serialised): + config = configparser.ConfigParser(interpolation = None) + config.read_string(serialised) #Read the input string as config file. + + #Checking file correctness. + if not config.has_section("general"): + raise SettingsError.InvalidFormatError("general") + if not config.has_option("general", "version"): + raise SettingsError.InvalidFormatError("general/version") + if not config.has_option("general", "name"): + raise SettingsError.InvalidFormatError("general/name") + if not config.has_option("general", "type"): + raise SettingsError.InvalidFormatError("general/type") + if int(config.get("general", "version")) != 1: #Explicitly hard-code version 1, since if this number changes the programmer MUST change this entire function. + raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") + + self._type_name = config.get("general", "type") + self._variant_name = config.get("general", "variant", fallback = None) + self._name = config.get("general", "name") + self._key = config.get("general", "key", fallback = None) + self._active_profile_name = config.get("general", "active_profile", fallback = None) + self._active_material_name = config.get("general", "material", fallback = None) + + self._machine_setting_overrides = {} + for key, value in config["machine_settings"].items(): + self._machine_setting_overrides[key] = value + ## Serialises this machine instance as file format version 2. # # \return A serialised form of this machine instance, serialised in # version 2 of the file format. def exportVersion2(): - raise Exception("Not implemented yet.") \ No newline at end of file + config = configparser.ConfigParser(interpolation = None) #Build a config file in the form of version 2. + + config.add_section("general") + config.set("general", "name", self._name) + config.set("general", "type", self._type_name) + config.set("general", "version", 2) #Hard-code version 2, since if this number changes the programmer MUST change this entire function. + if self._variant_name: + config.set("general", "variant", self._variant_name) + if self._key: + config.set("general", "key", self._key) + if self._active_profile_name: + config.set("general", "active_profile", self._active_profile_name) + if self._active_material_name: + config.set("general", "material", self._active_material_name) + + config.add_section("machine_settings") + for key, value in self._machine_setting_overrides.items(): + #TODO: Filter these through a translation dictionary. + config.set("machine_settings", key, value) + + output = io.StringIO() + config.write(output) + return output.getvalue() \ No newline at end of file From 242559bd7ebc5c72c67d8dc7749ec7ea406f7a04 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 13:53:56 +0200 Subject: [PATCH 03/62] Remove preferences upgrade from 2.1->2.2 No preferences will need to be upgraded. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/Preferences.py | 20 ------------------- .../VersionUpgrade21to22.py | 13 +----------- .../VersionUpgrade21to22/__init__.py | 4 ---- 3 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py deleted file mode 100644 index 7027ce960f..0000000000 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2015 Ultimaker B.V. -# Cura is released under the terms of the AGPLv3 or higher. - -## Creates a new preferences instance by parsing a serialised preferences file -# in version 2 of the file format. -# -# \param serialised The serialised form of a preferences file in version 2. -# \return A preferences instance, or None if the file format is incorrect. -def importVersion2(serialised): - return None #Not implemented yet. - -## A representation of a preferences file used as intermediary form for -# conversion from one format to the other. -class Preferences: - ## Serialises this preferences file as file format version 3. - # - # \return A serialised form of this preferences file, serialised in - # version 3 of the file format. - def exportVersion3(): - raise Exception("Not implemented yet.") \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 5a333c8f5b..dc7012e86b 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -9,7 +9,7 @@ from . import Profile #To upgrade profiles. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. # -# It converts the machine instances, preferences and profiles. +# It converts the machine instances and profiles. class VersionUpgrade21to22(VersionUpgrade): ## Converts machine instances from format version 1 to version 2. # @@ -22,17 +22,6 @@ class VersionUpgrade21to22(VersionUpgrade): return None return machine_instance.exportVersion2() - ## Converts preferences from format version 2 to version 3. - # - # \param serialised The serialised preferences file in version 2. - # \return The serialised preferences file in version 3, or None if the - # input was not of the correct format. - def upgradePreferences(self, serialised): - preferences = Preferences.importVersion2(serialised) - if not preferences: #Invalid file format. - return None - return preferences.exportVersion3() - ## Converts profiles from format version 1 to version 2. # # \param serialised The serialised profile in version 1. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 76546d1dd2..a8e976853f 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -20,10 +20,6 @@ def getMetaData(): "from": 1, "to": 2 }, - "preferences": { - "from": 2, - "to": 3 - }, "machine_instance": { "from": 1, "to": 2 From 00f356f06e47778ad49b7e9e3cadc378cc6a324b Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 15:24:28 +0200 Subject: [PATCH 04/62] Add translation of speed_support_lines This setting had its key changed to speed_support_infill Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index f924f4756d..ae8cb68cc2 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -50,6 +50,8 @@ class MachineInstance: ## Serialises this machine instance as file format version 2. # + # This is where the actual translation happens in this case. + # # \return A serialised form of this machine instance, serialised in # version 2 of the file format. def exportVersion2(): @@ -70,7 +72,8 @@ class MachineInstance: config.add_section("machine_settings") for key, value in self._machine_setting_overrides.items(): - #TODO: Filter these through a translation dictionary. + if key == "speed_support_lines": #Setting key was changed for 2.2. + key = "speed_support_infill" config.set("machine_settings", key, value) output = io.StringIO() From 9bc5f979029d1350772f1079891951e1b8c30b42 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 15:59:19 +0200 Subject: [PATCH 05/62] Implement conversion of profiles 2.1->2.2 This works more or less the same as for machine instances. The code was copied from version 2.1 of the unserialise function of profiles, and optimised a bit. The output function is written from scratch. It has some code duplication. Maybe we have to do something about that. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/Profile.py | 99 ++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 50d5b82b31..f5bda015d5 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -1,20 +1,113 @@ -# Copyright (c) 2015 Ultimaker B.V. +# Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. +import UM.SettingsError #To indicate that a file is of incorrect format. + +import configparser #To read config files. +import io #To write config files to strings as if they were files. + ## Creates a new profile instance by parsing a serialised profile in version 1 # of the file format. # # \param serialised The serialised form of a profile in version 1. # \return A profile instance, or None if the file format is incorrect. def importVersion1(serialised): - return None #Not implemented yet. + return Profile(serialised) ## A representation of a profile used as intermediary form for conversion from # one format to the other. class Profile: + ## Reads version 1 of the file format, storing it in memory. + # + # \param serialised A string with the contents of a machine instance file. + def __init__(self, serialised): + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialised) + + #Check correctness. + if not parser.has_section("general"): + raise SettingsError.InvalidFormatError("general") + if not parser.has_option("general", "version") or int(parser.get("general", "version")) != 1: #Hard-coded profile version here. If this number changes the entire function needs to change. + raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") + + #Parse the general section. + self._name = parser.get("general", "name") + self._type = parser.get("general", "type", fallback = None) + if "weight" in parser["general"]: + self._weight = int(parser.get("general", "weight")) + else: + self._weight = None + self._machine_type_id = parser.get("general", "machine_type", fallback = None) + self._machine_variant_name = parser.get("general", "machine_variant", fallback = None) + self._machine_instance_name = parser.get("general", "machine_instance", fallback = None) + if "material" in parser["general"]: + self._material_name = parser.get("general", "material") + elif self._type == "material": + self._material_name = parser.get("general", "name", fallback = None) + else: + self._material_name = None + + #Parse the settings. + self._settings = {} + if parser.has_section("settings"): + for key, value in parser["settings"].items(): + self._settings[key] = value + + #Parse the defaults and the disabled defaults. + self._changed_settings_defaults = {} + if parser.has_section("defaults"): + for key, value in parser["defaults"].items(): + self._changed_settings_defaults[key] = value + self._disabled_settings_defaults = [] + if parser.has_section("disabled_defaults"): + disabled_defaults_string = parser.get("disabled_defaults", "values") + for item in disabled_defaults_string.split(","): + if item != "": + self._disabled_settings_defaults.append(item) + ## Serialises this profile as file format version 2. # # \return A serialised form of this profile, serialised in version 2 of # the file format. def exportVersion2(): - raise Exception("Not implemented yet.") \ No newline at end of file + config = configparser.ConfigParser(interpolation = None) + + config.add_section("general") + config.set("general", "version", "2") #Hard-coded profile version 2 + config.set("general", "name", self._name) + if self._type: + config.set("general", "type", self._type) + if self._weight: + config.set("general", "weight", self._weight) + if self._machine_type_id: + config.set("general", "machine_type", self._machine_type_id) + if self._machine_variant_name: + config.set("general", "machine_variant", self._machine_variant_name) + if self._machine_instance_name: + config.set("general", "machine_instance", self._machine_instance_name) + if self._material_name and self._type != "material": + config.set("general", "material", self._material_name) + + if self._settings: + config.add_section("settings") + for key, value in self._settings.items(): + if key == "speed_support_lines": #Setting key was changed for 2.2. + key = "speed_support_infill" + config.set("settings", key, value) + + if self._changed_settings_defaults: + config.add_section("defaults") + for key, value in self._changed_settings_defaults.items(): + if key == "speed_support_lines": #Setting key was changed for 2.2. + key = "speed_support_infill" + config.set("defaults", key, value) + + if self._disabled_settings_defaults: + config.add_section("disabled_defaults") + disabled_defaults_string = str(self._disabled_settings_defaults[0]) #Must be at least 1 item, otherwise we wouldn't enter this if statement. + for item in self._disabled_settings_defaults[1:]: + disabled_defaults_string += "," + str(item) + + output = io.StringIO() + config.write(output) + return output.getvalue() \ No newline at end of file From 0d553c10f17204625115bd77a127c52bd9041770 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 16:05:38 +0200 Subject: [PATCH 06/62] Fix import of SettingsError It is in a submodule. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 +- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index ae8cb68cc2..2291adf92b 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -1,7 +1,7 @@ # Copyright (c) 2015 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -import UM.SettingsError #To indicate that a file is of incorrect format. +import UM.Settings.SettingsError #To indicate that a file is of incorrect format. import configparser #To read config files. import io #To write config files to strings as if they were files. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index f5bda015d5..8fd48745b1 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -1,7 +1,7 @@ # Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -import UM.SettingsError #To indicate that a file is of incorrect format. +import UM.Settings.SettingsError #To indicate that a file is of incorrect format. import configparser #To read config files. import io #To write config files to strings as if they were files. From 724f9ce0106a598421a57c3bf24efd3579fd28f3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 16:08:47 +0200 Subject: [PATCH 07/62] Return None if config file wasn't correct This was actually specified in the original function description. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 5 ++++- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 2291adf92b..1a6f7b9da9 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -13,7 +13,10 @@ import io #To write config files to strings as if they were files. # \return A machine instance instance, or None if the file format is # incorrect. def importVersion1(serialised): - return MachineInstance(serialised) + try: + return MachineInstance(serialised) + except configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError: + return None ## A representation of a machine instance used as intermediary form for # conversion from one format to the other. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 8fd48745b1..52180b72e0 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -12,7 +12,10 @@ import io #To write config files to strings as if they were files. # \param serialised The serialised form of a profile in version 1. # \return A profile instance, or None if the file format is incorrect. def importVersion1(serialised): - return Profile(serialised) + try: + return Profile(serialised) + except configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError: + return None ## A representation of a profile used as intermediary form for conversion from # one format to the other. From ccf9796b5108294c04e7c58b6b3e1f2130bf3244 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 16:09:32 +0200 Subject: [PATCH 08/62] Remove superfluous import Preferences doesn't exist any more. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index dc7012e86b..385001a3e6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -4,7 +4,6 @@ from UM.VersionUpgrade import VersionUpgrade #Superclass of the plugin. from . import MachineInstance #To upgrade machine instances. -from . import Preferences #To upgrade preferences. from . import Profile #To upgrade profiles. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. From 816e94c7603c5e2c63dbbf90182e748d3f75c9ed Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 16:12:13 +0200 Subject: [PATCH 09/62] Fix multiple exceptions Turns out that this syntax needs to be surrounded in brackets. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 +- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 1a6f7b9da9..8799c32b46 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -15,7 +15,7 @@ import io #To write config files to strings as if they were files. def importVersion1(serialised): try: return MachineInstance(serialised) - except configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError: + except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): return None ## A representation of a machine instance used as intermediary form for diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 52180b72e0..65fc243de6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -14,7 +14,7 @@ import io #To write config files to strings as if they were files. def importVersion1(serialised): try: return Profile(serialised) - except configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError: + except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): return None ## A representation of a profile used as intermediary form for conversion from From aeecdd9e0e95d62e76dffc36cb23ddc7c83014fc Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 16:31:22 +0200 Subject: [PATCH 10/62] Add self to parameters of function Yeah this was a method, not a static method. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 8799c32b46..5b29800d5f 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -57,7 +57,7 @@ class MachineInstance: # # \return A serialised form of this machine instance, serialised in # version 2 of the file format. - def exportVersion2(): + def exportVersion2(self): config = configparser.ConfigParser(interpolation = None) #Build a config file in the form of version 2. config.add_section("general") From 149e873eb6ed8b2d99289cbdf7f42225b82f795a Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 17:26:28 +0200 Subject: [PATCH 11/62] Pass strings to writing configparser When setting fields in configparser, it must be a string. No ints. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 4 ++-- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 5b29800d5f..038d35bee0 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -63,7 +63,7 @@ class MachineInstance: config.add_section("general") config.set("general", "name", self._name) config.set("general", "type", self._type_name) - config.set("general", "version", 2) #Hard-code version 2, since if this number changes the programmer MUST change this entire function. + config.set("general", "version", "2") #Hard-code version 2, since if this number changes the programmer MUST change this entire function. if self._variant_name: config.set("general", "variant", self._variant_name) if self._key: @@ -77,7 +77,7 @@ class MachineInstance: for key, value in self._machine_setting_overrides.items(): if key == "speed_support_lines": #Setting key was changed for 2.2. key = "speed_support_infill" - config.set("machine_settings", key, value) + config.set("machine_settings", key, str(value)) output = io.StringIO() config.write(output) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 65fc243de6..d9e00bf85d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -96,14 +96,14 @@ class Profile: for key, value in self._settings.items(): if key == "speed_support_lines": #Setting key was changed for 2.2. key = "speed_support_infill" - config.set("settings", key, value) + config.set("settings", key, str(value)) if self._changed_settings_defaults: config.add_section("defaults") for key, value in self._changed_settings_defaults.items(): if key == "speed_support_lines": #Setting key was changed for 2.2. key = "speed_support_infill" - config.set("defaults", key, value) + config.set("defaults", key, str(value)) if self._disabled_settings_defaults: config.add_section("disabled_defaults") From 17f47033373727473d8c0c457cb7dc05a224d291 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 19 Apr 2016 17:28:26 +0200 Subject: [PATCH 12/62] Fix self parameter It must have access to self to get the values to store in the file. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index d9e00bf85d..fe0a48f6d0 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -72,7 +72,7 @@ class Profile: # # \return A serialised form of this profile, serialised in version 2 of # the file format. - def exportVersion2(): + def exportVersion2(self): config = configparser.ConfigParser(interpolation = None) config.add_section("general") From f7be4831b856d64655d4fcaee84edb7f9f09276c Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 20 Apr 2016 12:04:22 +0200 Subject: [PATCH 13/62] Add translation for combing Combing was made into an enum instead of a boolean. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 ++ plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 038d35bee0..5e90e27f17 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -77,6 +77,8 @@ class MachineInstance: for key, value in self._machine_setting_overrides.items(): if key == "speed_support_lines": #Setting key was changed for 2.2. key = "speed_support_infill" + if key == "retraction_combing": #Combing was made into an enum instead of a boolean. + value = "off" if (value == "False") else "all" config.set("machine_settings", key, str(value)) output = io.StringIO() diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index fe0a48f6d0..a70293f8b9 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -96,6 +96,8 @@ class Profile: for key, value in self._settings.items(): if key == "speed_support_lines": #Setting key was changed for 2.2. key = "speed_support_infill" + if key == "retraction_combing": #Combing was made into an enum instead of a boolean. + value = "off" if (value == "False") else "all" config.set("settings", key, str(value)) if self._changed_settings_defaults: @@ -103,6 +105,8 @@ class Profile: for key, value in self._changed_settings_defaults.items(): if key == "speed_support_lines": #Setting key was changed for 2.2. key = "speed_support_infill" + if key == "retraction_combing": #Combing was made into an enum instead of a boolean. + value = "off" if (value == "False") else "all" config.set("defaults", key, str(value)) if self._disabled_settings_defaults: From cce642a3e1ae2b4500fb5e4ea335254b2c636678 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 20 Apr 2016 12:58:17 +0200 Subject: [PATCH 14/62] Extrapolate settings translations It is now in one place. Or rather, two: There is another function to translate only setting names. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 6 ++-- .../VersionUpgrade21to22/Profile.py | 12 +++---- .../VersionUpgrade21to22.py | 33 ++++++++++++++++++- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 5e90e27f17..4b9d7b8be5 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -58,6 +58,7 @@ class MachineInstance: # \return A serialised form of this machine instance, serialised in # version 2 of the file format. def exportVersion2(self): + import VersionUpgrade21to22 #Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) #Build a config file in the form of version 2. config.add_section("general") @@ -73,12 +74,9 @@ class MachineInstance: if self._active_material_name: config.set("general", "material", self._active_material_name) + VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) config.add_section("machine_settings") for key, value in self._machine_setting_overrides.items(): - if key == "speed_support_lines": #Setting key was changed for 2.2. - key = "speed_support_infill" - if key == "retraction_combing": #Combing was made into an enum instead of a boolean. - value = "off" if (value == "False") else "all" config.set("machine_settings", key, str(value)) output = io.StringIO() diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index a70293f8b9..8a461dad6a 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -73,6 +73,7 @@ class Profile: # \return A serialised form of this profile, serialised in version 2 of # the file format. def exportVersion2(self): + import VersionUpgrade21to22 #Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) config.add_section("general") @@ -92,24 +93,19 @@ class Profile: config.set("general", "material", self._material_name) if self._settings: + VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) config.add_section("settings") for key, value in self._settings.items(): - if key == "speed_support_lines": #Setting key was changed for 2.2. - key = "speed_support_infill" - if key == "retraction_combing": #Combing was made into an enum instead of a boolean. - value = "off" if (value == "False") else "all" config.set("settings", key, str(value)) if self._changed_settings_defaults: + VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._changed_settings_defaults) config.add_section("defaults") for key, value in self._changed_settings_defaults.items(): - if key == "speed_support_lines": #Setting key was changed for 2.2. - key = "speed_support_infill" - if key == "retraction_combing": #Combing was made into an enum instead of a boolean. - value = "off" if (value == "False") else "all" config.set("defaults", key, str(value)) if self._disabled_settings_defaults: + VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(self._disabled_settings_defaults) config.add_section("disabled_defaults") disabled_defaults_string = str(self._disabled_settings_defaults[0]) #Must be at least 1 item, otherwise we wouldn't enter this if statement. for item in self._disabled_settings_defaults[1:]: diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 385001a3e6..cc248d3d51 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -30,4 +30,35 @@ class VersionUpgrade21to22(VersionUpgrade): profile = Profile.importVersion1(serialised) if not profile: #Invalid file format. return None - return profile.exportVersion2() \ No newline at end of file + return profile.exportVersion2() + + ## Translates settings for the change from Cura 2.1 to 2.2. + # + # Each setting is changed in-place in the provided dictionary. This changes + # the input parameter. + # + # \param settings A dictionary of settings (as key-value pairs) to update. + # \return The same dictionary. + @staticmethod + def translateSettings(settings): + for key, value in settings.items(): + if key == "speed_support_lines": #Setting key was changed for 2.2. + del settings[key] + settings["speed_support_infill"] = value + if key == "retraction_combing": #Combing was made into an enum instead of a boolean. + settings[key] = "off" if (value == "False") else "all" + return settings + + ## Translates setting names for the change from Cura 2.1 to 2.2. + # + # The setting names are changed in-place in the provided list. This changes + # the input parameter. + # + # \param settings A list of setting names to update. + # \return The same list. + @staticmethod + def translateSettingNames(settings): + for i in range(0, len(settings)): + if settings[i] == "speed_support_lines": + settings[i] = "speed_support_infill" + return settings \ No newline at end of file From 41ee575cc1bfdc769bde94d9d81d8146498e46ce Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 12:03:12 +0200 Subject: [PATCH 15/62] Correct copyright year These files were made in 2016. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 +- .../VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py | 2 +- plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 4b9d7b8be5..e4f067b5f3 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015 Ultimaker B.V. +# Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. import UM.Settings.SettingsError #To indicate that a file is of incorrect format. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index cc248d3d51..17f0154168 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015 Ultimaker B.V. +# Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. from UM.VersionUpgrade import VersionUpgrade #Superclass of the plugin. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index a8e976853f..36b6d6609a 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015 Ultimaker B.V. +# Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. from . import VersionUpgrade21to22 From 0e92929be486666f25fc79e0deb0a8aa929cdf95 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 12:07:51 +0200 Subject: [PATCH 16/62] Codestyle: Wrap doxygen documentation at 80 chars Contributes to issue CURA-844. --- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 17f0154168..0118a96aa8 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -34,8 +34,8 @@ class VersionUpgrade21to22(VersionUpgrade): ## Translates settings for the change from Cura 2.1 to 2.2. # - # Each setting is changed in-place in the provided dictionary. This changes - # the input parameter. + # Each setting is changed in-place in the provided dictionary. This + # changes the input parameter. # # \param settings A dictionary of settings (as key-value pairs) to update. # \return The same dictionary. From 7ad2fbc95d3ed440aac561557d833f3614944dcf Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 12:15:43 +0200 Subject: [PATCH 17/62] Codestyle: Start comments with space We didn't really discuss this one, but apparently it's in PEP8 so I'd better do it. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 12 ++++++------ .../VersionUpgrade/VersionUpgrade21to22/Profile.py | 14 +++++++------- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index e4f067b5f3..10eb3a0607 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -26,9 +26,9 @@ class MachineInstance: # \param serialised A string with the contents of a machine instance file. def __init__(self, serialised): config = configparser.ConfigParser(interpolation = None) - config.read_string(serialised) #Read the input string as config file. + config.read_string(serialised) # Read the input string as config file. - #Checking file correctness. + # Checking file correctness. if not config.has_section("general"): raise SettingsError.InvalidFormatError("general") if not config.has_option("general", "version"): @@ -37,7 +37,7 @@ class MachineInstance: raise SettingsError.InvalidFormatError("general/name") if not config.has_option("general", "type"): raise SettingsError.InvalidFormatError("general/type") - if int(config.get("general", "version")) != 1: #Explicitly hard-code version 1, since if this number changes the programmer MUST change this entire function. + if int(config.get("general", "version")) != 1: # Explicitly hard-code version 1, since if this number changes the programmer MUST change this entire function. raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") self._type_name = config.get("general", "type") @@ -58,13 +58,13 @@ class MachineInstance: # \return A serialised form of this machine instance, serialised in # version 2 of the file format. def exportVersion2(self): - import VersionUpgrade21to22 #Import here to prevent circular dependencies. - config = configparser.ConfigParser(interpolation = None) #Build a config file in the form of version 2. + import VersionUpgrade21to22 # Import here to prevent circular dependencies. + config = configparser.ConfigParser(interpolation = None) # Build a config file in the form of version 2. config.add_section("general") config.set("general", "name", self._name) config.set("general", "type", self._type_name) - config.set("general", "version", "2") #Hard-code version 2, since if this number changes the programmer MUST change this entire function. + config.set("general", "version", "2") # Hard-code version 2, since if this number changes the programmer MUST change this entire function. if self._variant_name: config.set("general", "variant", self._variant_name) if self._key: diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 8a461dad6a..c2eed5d47f 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -27,13 +27,13 @@ class Profile: parser = configparser.ConfigParser(interpolation = None) parser.read_string(serialised) - #Check correctness. + # Check correctness. if not parser.has_section("general"): raise SettingsError.InvalidFormatError("general") if not parser.has_option("general", "version") or int(parser.get("general", "version")) != 1: #Hard-coded profile version here. If this number changes the entire function needs to change. raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") - #Parse the general section. + # Parse the general section. self._name = parser.get("general", "name") self._type = parser.get("general", "type", fallback = None) if "weight" in parser["general"]: @@ -50,13 +50,13 @@ class Profile: else: self._material_name = None - #Parse the settings. + # Parse the settings. self._settings = {} if parser.has_section("settings"): for key, value in parser["settings"].items(): self._settings[key] = value - #Parse the defaults and the disabled defaults. + # Parse the defaults and the disabled defaults. self._changed_settings_defaults = {} if parser.has_section("defaults"): for key, value in parser["defaults"].items(): @@ -73,11 +73,11 @@ class Profile: # \return A serialised form of this profile, serialised in version 2 of # the file format. def exportVersion2(self): - import VersionUpgrade21to22 #Import here to prevent circular dependencies. + import VersionUpgrade21to22 # Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) config.add_section("general") - config.set("general", "version", "2") #Hard-coded profile version 2 + config.set("general", "version", "2") # Hard-coded profile version 2 config.set("general", "name", self._name) if self._type: config.set("general", "type", self._type) @@ -107,7 +107,7 @@ class Profile: if self._disabled_settings_defaults: VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(self._disabled_settings_defaults) config.add_section("disabled_defaults") - disabled_defaults_string = str(self._disabled_settings_defaults[0]) #Must be at least 1 item, otherwise we wouldn't enter this if statement. + disabled_defaults_string = str(self._disabled_settings_defaults[0]) # Must be at least 1 item, otherwise we wouldn't enter this if statement. for item in self._disabled_settings_defaults[1:]: disabled_defaults_string += "," + str(item) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 0118a96aa8..076bd7cc5e 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -1,10 +1,10 @@ # Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -from UM.VersionUpgrade import VersionUpgrade #Superclass of the plugin. +from UM.VersionUpgrade import VersionUpgrade # Superclass of the plugin. -from . import MachineInstance #To upgrade machine instances. -from . import Profile #To upgrade profiles. +from . import MachineInstance # To upgrade machine instances. +from . import Profile # To upgrade profiles. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. # @@ -28,7 +28,7 @@ class VersionUpgrade21to22(VersionUpgrade): # not of the correct format. def upgradeProfile(self, serialised): profile = Profile.importVersion1(serialised) - if not profile: #Invalid file format. + if not profile: # Invalid file format. return None return profile.exportVersion2() @@ -42,10 +42,10 @@ class VersionUpgrade21to22(VersionUpgrade): @staticmethod def translateSettings(settings): for key, value in settings.items(): - if key == "speed_support_lines": #Setting key was changed for 2.2. + if key == "speed_support_lines": # Setting key was changed for 2.2. del settings[key] settings["speed_support_infill"] = value - if key == "retraction_combing": #Combing was made into an enum instead of a boolean. + if key == "retraction_combing": # Combing was made into an enum instead of a boolean. settings[key] = "off" if (value == "False") else "all" return settings From fdf37c2ab01dbff71005373dfda9afdf53ca67e8 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 12:21:32 +0200 Subject: [PATCH 18/62] Codestyle: Start comments with space Forgot this one. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index c2eed5d47f..5c4afb864b 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -30,7 +30,7 @@ class Profile: # Check correctness. if not parser.has_section("general"): raise SettingsError.InvalidFormatError("general") - if not parser.has_option("general", "version") or int(parser.get("general", "version")) != 1: #Hard-coded profile version here. If this number changes the entire function needs to change. + if not parser.has_option("general", "version") or int(parser.get("general", "version")) != 1: # Hard-coded profile version here. If this number changes the entire function needs to change. raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") # Parse the general section. From f2f993916d72e19c207d24537aef459aacf1b943 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 12:27:39 +0200 Subject: [PATCH 19/62] Rename import/export functions They no longer mention the version number in their function names. I'd rather have named them import/export but that gave a name clash with Python's 'import' keyword. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 4 ++-- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 4 ++-- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 10eb3a0607..06438d994d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -12,7 +12,7 @@ import io #To write config files to strings as if they were files. # \param serialised The serialised form of a machine instance in version 1. # \return A machine instance instance, or None if the file format is # incorrect. -def importVersion1(serialised): +def importFrom(serialised): try: return MachineInstance(serialised) except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): @@ -57,7 +57,7 @@ class MachineInstance: # # \return A serialised form of this machine instance, serialised in # version 2 of the file format. - def exportVersion2(self): + def exportTo(self): import VersionUpgrade21to22 # Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) # Build a config file in the form of version 2. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 5c4afb864b..22b68bdbbf 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -11,7 +11,7 @@ import io #To write config files to strings as if they were files. # # \param serialised The serialised form of a profile in version 1. # \return A profile instance, or None if the file format is incorrect. -def importVersion1(serialised): +def importFrom(serialised): try: return Profile(serialised) except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): @@ -72,7 +72,7 @@ class Profile: # # \return A serialised form of this profile, serialised in version 2 of # the file format. - def exportVersion2(self): + def exportTo(self): import VersionUpgrade21to22 # Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 076bd7cc5e..9312da690d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -16,10 +16,10 @@ class VersionUpgrade21to22(VersionUpgrade): # \return The serialised machine instance in version 2, or None if the # input was not of the correct format. def upgradeMachineInstance(self, serialised): - machine_instance = MachineInstance.importVersion1(serialised) + machine_instance = MachineInstance.importFrom(serialised) if not machine_instance: #Invalid file format. return None - return machine_instance.exportVersion2() + return machine_instance.exportTo() ## Converts profiles from format version 1 to version 2. # @@ -27,10 +27,10 @@ class VersionUpgrade21to22(VersionUpgrade): # \return The serialised profile in version 2, or None if the input was # not of the correct format. def upgradeProfile(self, serialised): - profile = Profile.importVersion1(serialised) + profile = Profile.importFrom(serialised) if not profile: # Invalid file format. return None - return profile.exportVersion2() + return profile.exportTo() ## Translates settings for the change from Cura 2.1 to 2.2. # From f7ca48987703007896b6170790d03438369451dd Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 12:29:14 +0200 Subject: [PATCH 20/62] Rename exportTo -> export Because exportTo doesn't make sense if there is no parameter to which we're exporting. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 +- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 2 +- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 06438d994d..bf01c877ff 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -57,7 +57,7 @@ class MachineInstance: # # \return A serialised form of this machine instance, serialised in # version 2 of the file format. - def exportTo(self): + def export(self): import VersionUpgrade21to22 # Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) # Build a config file in the form of version 2. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 22b68bdbbf..52518f3502 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -72,7 +72,7 @@ class Profile: # # \return A serialised form of this profile, serialised in version 2 of # the file format. - def exportTo(self): + def export(self): import VersionUpgrade21to22 # Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 9312da690d..303a6c0634 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -19,7 +19,7 @@ class VersionUpgrade21to22(VersionUpgrade): machine_instance = MachineInstance.importFrom(serialised) if not machine_instance: #Invalid file format. return None - return machine_instance.exportTo() + return machine_instance.export() ## Converts profiles from format version 1 to version 2. # @@ -30,7 +30,7 @@ class VersionUpgrade21to22(VersionUpgrade): profile = Profile.importFrom(serialised) if not profile: # Invalid file format. return None - return profile.exportTo() + return profile.export() ## Translates settings for the change from Cura 2.1 to 2.2. # From 28da3c1a4ff5b1bef294fea0281a1bd1ac8ae5a6 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 13:10:18 +0200 Subject: [PATCH 21/62] Improve documentation for translate function It says now that the function updates the settings to what they should be in the new version. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 303a6c0634..4a8a4652ad 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -32,10 +32,11 @@ class VersionUpgrade21to22(VersionUpgrade): return None return profile.export() - ## Translates settings for the change from Cura 2.1 to 2.2. + ## Updates settings for the change from Cura 2.1 to 2.2. # - # Each setting is changed in-place in the provided dictionary. This - # changes the input parameter. + # The keys and values of settings are changed to what they should be in + # the new version. Each setting is changed in-place in the provided + # dictionary. This changes the input parameter. # # \param settings A dictionary of settings (as key-value pairs) to update. # \return The same dictionary. From 6572d939bf841da1a63791f8cf21050bdbd71601 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 28 Apr 2016 14:09:40 +0200 Subject: [PATCH 22/62] Convert for+if to list comprehension It's a simple filter, so why not? Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 52518f3502..d3c2ba3233 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -64,9 +64,7 @@ class Profile: self._disabled_settings_defaults = [] if parser.has_section("disabled_defaults"): disabled_defaults_string = parser.get("disabled_defaults", "values") - for item in disabled_defaults_string.split(","): - if item != "": - self._disabled_settings_defaults.append(item) + self._disabled_settings_defaults = [item for item in disabled_defaults_string.split(",") if item != ""] # Split by comma. ## Serialises this profile as file format version 2. # From 8a44705413d3a01e897d4a922e7c1383b60a2927 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 10:52:42 +0200 Subject: [PATCH 23/62] Update metadata with dynamic config types After settings rework, we decided to make the upgrade plug-ins define their own configuration types. This is basically the definition for these configuration types. Only the get_version function is not yet implemented. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/__init__.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 36b6d6609a..2607b92e6a 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -16,13 +16,23 @@ def getMetaData(): "api": 2 }, "version_upgrade": { + # From To Upgrade function + ("profile", 1): ("instance_container", 2, VersionUpgrade21to22.upgradeProfile), + ("machine_instance", 1): ("container_stack", 2, VersionUpgrade21to22.upgradeMachineInstance), + ("preferences", 1): ("preferences", 2, VersionUpgrade21to22.upgradePreferences) + }, + "sources": { "profile": { - "from": 1, - "to": 2 + "get_version": VersionUpgrade21to22.getCfgVersion, + "location": {"./profiles"} }, "machine_instance": { - "from": 1, - "to": 2 + "get_version": VersionUpgrade21to22.getCfgVersion, + "location": {"./machine_instances"} + }, + "preferences": { + "get_version": VersionUpgrade21to22.getCfgVersion, + "location": {"."} } } } From 5143d0b9f15b5d61ad081d852d347a4da7c5b8a4 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 12:03:44 +0200 Subject: [PATCH 24/62] Implement getCfgVersion This code is basically moved from Uranium to here. This is needed to allow for upgrade plug-ins to define their own configuration types. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 4a8a4652ad..77669f2b56 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -1,11 +1,25 @@ # Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. +import configparser #To get version numbers from config files. + from UM.VersionUpgrade import VersionUpgrade # Superclass of the plugin. from . import MachineInstance # To upgrade machine instances. from . import Profile # To upgrade profiles. +## Gets the version number from a config file. +# +# In all config files that concern this version upgrade, the version +# number is stored in general/version, so get the data from that key. +# +# \param serialised The contents of a config file. +# \return \type{int} The version number of that config file. +def getCfgVersion(serialised): + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialised) + return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised. + ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. # # It converts the machine instances and profiles. From 68afd08afd93b64ebdb18d9e60188b710449d80c Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 12:42:27 +0200 Subject: [PATCH 25/62] Fix links to upgrade functions These are bound methods of an instance. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/__init__.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 2607b92e6a..53d3814a94 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -6,6 +6,8 @@ from . import VersionUpgrade21to22 from UM.i18n import i18nCatalog catalog = i18nCatalog("cura") +upgrade = VersionUpgrade21to22.VersionUpgrade21to22() + def getMetaData(): return { "plugin": { @@ -17,25 +19,25 @@ def getMetaData(): }, "version_upgrade": { # From To Upgrade function - ("profile", 1): ("instance_container", 2, VersionUpgrade21to22.upgradeProfile), - ("machine_instance", 1): ("container_stack", 2, VersionUpgrade21to22.upgradeMachineInstance), - ("preferences", 1): ("preferences", 2, VersionUpgrade21to22.upgradePreferences) + ("profile", 1): ("instance_container", 2, upgrade.upgradeProfile), + ("machine_instance", 1): ("container_stack", 2, upgrade.upgradeMachineInstance), + ("preferences", 1): ("preferences", 2, upgrade.upgradePreferences) }, "sources": { "profile": { - "get_version": VersionUpgrade21to22.getCfgVersion, + "get_version": upgrade.getCfgVersion, "location": {"./profiles"} }, "machine_instance": { - "get_version": VersionUpgrade21to22.getCfgVersion, + "get_version": upgrade.getCfgVersion, "location": {"./machine_instances"} }, "preferences": { - "get_version": VersionUpgrade21to22.getCfgVersion, + "get_version": upgrade.getCfgVersion, "location": {"."} } } } def register(app): - return { "version_upgrade": VersionUpgrade21to22.VersionUpgrade21to22() } + return { "version_upgrade": upgrade } From c1b738953b621b09664a4b77802bc6e5f6fdff94 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 12:47:12 +0200 Subject: [PATCH 26/62] Align documentation better I just couldn't stand it... 'I have to sort my books', she cried With self-indulgent glee With senseless, narcissistic pride: 'I'm just so OCD' 'How random, guys', I smiled and said Then left without a peep And washed my hands until they bled And cried myself to sleep Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 53d3814a94..9e683be321 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -18,7 +18,7 @@ def getMetaData(): "api": 2 }, "version_upgrade": { - # From To Upgrade function + # From To Upgrade function ("profile", 1): ("instance_container", 2, upgrade.upgradeProfile), ("machine_instance", 1): ("container_stack", 2, upgrade.upgradeMachineInstance), ("preferences", 1): ("preferences", 2, upgrade.upgradePreferences) From 66df680e1b3d641b3ede9e58cc2f30c8f19328cb Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 12:53:53 +0200 Subject: [PATCH 27/62] Move getCfgVersion back inside class To ask the cfgversion from the actual plug-in is more object-oriented programming. Contributes to issue CURA-844. --- .../VersionUpgrade21to22.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 77669f2b56..b2404fb8f0 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -8,22 +8,22 @@ from UM.VersionUpgrade import VersionUpgrade # Superclass of the plugin. from . import MachineInstance # To upgrade machine instances. from . import Profile # To upgrade profiles. -## Gets the version number from a config file. -# -# In all config files that concern this version upgrade, the version -# number is stored in general/version, so get the data from that key. -# -# \param serialised The contents of a config file. -# \return \type{int} The version number of that config file. -def getCfgVersion(serialised): - parser = configparser.ConfigParser(interpolation = None) - parser.read_string(serialised) - return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised. - ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. # # It converts the machine instances and profiles. class VersionUpgrade21to22(VersionUpgrade): + ## Gets the version number from a config file. + # + # In all config files that concern this version upgrade, the version + # number is stored in general/version, so get the data from that key. + # + # \param serialised The contents of a config file. + # \return \type{int} The version number of that config file. + def getCfgVersion(self, serialised): + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialised) + return int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised. + ## Converts machine instances from format version 1 to version 2. # # \param serialised The serialised machine instance in version 1. From 24946d3f13205a854bf9ced48f127701ff4d6622 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 16:50:24 +0200 Subject: [PATCH 28/62] Fix references to exception classes These were moved to VersionUpgrade module. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 16 ++++++++-------- .../VersionUpgrade21to22/Profile.py | 16 +++++++++------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index bf01c877ff..ceb40fadd9 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -1,7 +1,7 @@ # Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -import UM.Settings.SettingsError #To indicate that a file is of incorrect format. +import UM.VersionUpgrade #To indicate that a file is of incorrect format. import configparser #To read config files. import io #To write config files to strings as if they were files. @@ -15,7 +15,7 @@ import io #To write config files to strings as if they were files. def importFrom(serialised): try: return MachineInstance(serialised) - except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): + except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException): return None ## A representation of a machine instance used as intermediary form for @@ -30,15 +30,15 @@ class MachineInstance: # Checking file correctness. if not config.has_section("general"): - raise SettingsError.InvalidFormatError("general") + raise UM.VersionUpgrade.FormatException("No \"general\" section.") if not config.has_option("general", "version"): - raise SettingsError.InvalidFormatError("general/version") + raise UM.VersionUpgrade.FormatException("No \"version\" in \"general\" section.") if not config.has_option("general", "name"): - raise SettingsError.InvalidFormatError("general/name") + raise UM.VersionUpgrade.FormatException("No \"name\" in \"general\" section.") if not config.has_option("general", "type"): - raise SettingsError.InvalidFormatError("general/type") + raise UM.VersionUpgrade.FormatException("No \"type\" in \"general\" section.") if int(config.get("general", "version")) != 1: # Explicitly hard-code version 1, since if this number changes the programmer MUST change this entire function. - raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") + raise UM.VersionUpgrade.InvalidVersionException("The version of this machine instance is wrong. It must be 1.") self._type_name = config.get("general", "type") self._variant_name = config.get("general", "variant", fallback = None) @@ -58,7 +58,6 @@ class MachineInstance: # \return A serialised form of this machine instance, serialised in # version 2 of the file format. def export(self): - import VersionUpgrade21to22 # Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) # Build a config file in the form of version 2. config.add_section("general") @@ -74,6 +73,7 @@ class MachineInstance: if self._active_material_name: config.set("general", "material", self._active_material_name) + import VersionUpgrade21to22 # Import here to prevent circular dependencies. VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) config.add_section("machine_settings") for key, value in self._machine_setting_overrides.items(): diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index d3c2ba3233..15cc01c2ea 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -1,11 +1,11 @@ # Copyright (c) 2016 Ultimaker B.V. # Cura is released under the terms of the AGPLv3 or higher. -import UM.Settings.SettingsError #To indicate that a file is of incorrect format. - import configparser #To read config files. import io #To write config files to strings as if they were files. +import UM.VersionUpgrade + ## Creates a new profile instance by parsing a serialised profile in version 1 # of the file format. # @@ -14,7 +14,7 @@ import io #To write config files to strings as if they were files. def importFrom(serialised): try: return Profile(serialised) - except (configparser.Error, SettingsError.InvalidFormatError, SettingsError.InvalidVersionError): + except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException): return None ## A representation of a profile used as intermediary form for conversion from @@ -29,9 +29,11 @@ class Profile: # Check correctness. if not parser.has_section("general"): - raise SettingsError.InvalidFormatError("general") - if not parser.has_option("general", "version") or int(parser.get("general", "version")) != 1: # Hard-coded profile version here. If this number changes the entire function needs to change. - raise SettingsError.InvalidVersionError("Version upgrade intermediary version 1") + raise UM.VersionUpgrade.FormatException("No \"general\" section.") + if not parser.has_option("general", "version"): + raise UM.VersionUpgrade.FormatException("No \"version\" in the \"general\" section.") + if int(parser.get("general", "version")) != 1: # Hard-coded profile version here. If this number changes the entire function needs to change. + raise UM.VersionUpgrade.InvalidVersionException("The version of this profile is wrong. It must be 1.") # Parse the general section. self._name = parser.get("general", "name") @@ -71,7 +73,6 @@ class Profile: # \return A serialised form of this profile, serialised in version 2 of # the file format. def export(self): - import VersionUpgrade21to22 # Import here to prevent circular dependencies. config = configparser.ConfigParser(interpolation = None) config.add_section("general") @@ -90,6 +91,7 @@ class Profile: if self._material_name and self._type != "material": config.set("general", "material", self._material_name) + import VersionUpgrade21to22 # Import here to prevent circular dependencies. if self._settings: VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) config.add_section("settings") From 11d59709efc5136fa5ea48b7b6e019d779eddf88 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 16:54:32 +0200 Subject: [PATCH 29/62] Add stub preferences converter Needs to be implemented like the rest of them. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index b2404fb8f0..adbde2ff0d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -35,6 +35,14 @@ class VersionUpgrade21to22(VersionUpgrade): return None return machine_instance.export() + ## Converts preferences from format version 1 to version 2. + # + # \param serialised The serialised preferences file in version 1. + # \return The serialised preferences in version 2, or None if the input + # was not of the correct format. + def upgradePreferences(self, serialised): + return serialised #TODO + ## Converts profiles from format version 1 to version 2. # # \param serialised The serialised profile in version 1. From f04430ba5732234ec6a2a21230c041a127fd825c Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 16:56:57 +0200 Subject: [PATCH 30/62] Increment plug-in API version It is now settings-rework-aware! Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 9e683be321..98593785c6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -15,7 +15,7 @@ def getMetaData(): "author": "Ultimaker", "version": "1.0", "description": catalog.i18nc("@info:whatsthis", "Upgrades configurations from Cura 2.1 to Cura 2.2."), - "api": 2 + "api": 3 }, "version_upgrade": { # From To Upgrade function From 04974a4308e45193c113dce7d3f9199def6d9446 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Jun 2016 13:46:08 +0200 Subject: [PATCH 31/62] Correct preferences version number The old version was 2, so the new one needs to be 3. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 98593785c6..02207bbd50 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -21,7 +21,7 @@ def getMetaData(): # From To Upgrade function ("profile", 1): ("instance_container", 2, upgrade.upgradeProfile), ("machine_instance", 1): ("container_stack", 2, upgrade.upgradeMachineInstance), - ("preferences", 1): ("preferences", 2, upgrade.upgradePreferences) + ("preferences", 2): ("preferences", 3, upgrade.upgradePreferences) }, "sources": { "profile": { From e02a633ef268a58a0054c0f9ab1a03dacdb3919f Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Jun 2016 15:49:31 +0200 Subject: [PATCH 32/62] Add preferences converter Currently it removes the expanded categories setting, and translates the setting names in the visibility. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/Preferences.py | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py new file mode 100644 index 0000000000..0ec76eba53 --- /dev/null +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -0,0 +1,61 @@ +# Copyright (c) 2016 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +import configparser #To read config files. +import io #To output config files to string. + +import UM.VersionUpgrade #To indicate that a file is of the wrong format. + +## Creates a new preferences instance by parsing a serialised preferences file +# in version 1 of the file format. +# +# \param serialised The serialised form of a preferences file in version 1. +# \return A representation of those preferences, or None if the file format is +# incorrect. +def importFrom(serialised): + try: + return Preferences(serialised) + except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException): + return None + +## A representation of preferences files as intermediary form for conversion +# from one format to the other. +class Preferences: + ## Reads version 2 of the preferences file format, storing it in memory. + # + # \param serialised A serialised version 2 preferences file. + def __init__(self, serialised): + self._config = configparser.ConfigParser(interpolation = None) + self._config.read_string(serialised) + + #Checking file correctness. + if not self._config.has_section("general"): + raise UM.VersionUpgrade.FormatException("No \"general\" section.") + if not self._config.has_option("general", "version"): + raise UM.VersionUpgrade.FormatException("No \"version\" in \"general\" section.") + if int(self._config.get("general", "version")) != 2: # Explicitly hard-code version 2, since if this number changes the programmer MUST change this entire function. + raise UM.VersionUpgrade.InvalidVersionException("The version of this preferences file is wrong. It must be 2.") + + ## Serialises these preferences as a preferences file of version 3. + # + # This is where the actual translation happens. + # + # \return A serialised version of a preferences file in version 3. + def export(self): + #Reset the cura/categories_expanded property since it works differently now. + if self._config.has_section("cura") and self._config.has_option("cura", "categories_expanded"): + self._config.remove_option("cura", "categories_expanded") + + #Translate the setting names in the visible settings. + if self._config.has_section("machines") and self._config.has_option("machines", "setting_visibility"): + visible_settings = self._config.get("machines", "setting_visibility") + visible_settings = visible_settings.split(",") + import VersionUpgrade21to22 #Import here to prevent a circular dependency. + visible_settings = VersionUpgrade21to22.translateSettingNames(visible_settings) + visible_settings = visible_settings.join(",") + self._config.set("machines", "setting_visibility", value = visible_settings) + + #Output the result as a string. + output = io.StringIO() + self._config.write(output) + return output.getvalue() \ No newline at end of file From ec5aee253d2ad1d78741e8ed796f491f583095bf Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Jun 2016 16:04:02 +0200 Subject: [PATCH 33/62] Also increment the version number Of course. Duh. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index 0ec76eba53..f4c5e89b92 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -55,6 +55,9 @@ class Preferences: visible_settings = visible_settings.join(",") self._config.set("machines", "setting_visibility", value = visible_settings) + #Update the version number itself. + self._config.set("general", "version", value = "3") + #Output the result as a string. output = io.StringIO() self._config.write(output) From 51aa82bd6c61ceb75c074b36d349e87fa2478282 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Jun 2016 16:18:04 +0200 Subject: [PATCH 34/62] Use preferences upgrader Instead of the placeholder. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index adbde2ff0d..a06369f301 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -6,6 +6,7 @@ import configparser #To get version numbers from config files. from UM.VersionUpgrade import VersionUpgrade # Superclass of the plugin. from . import MachineInstance # To upgrade machine instances. +from . import Preferences #To upgrade preferences. from . import Profile # To upgrade profiles. ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. @@ -35,13 +36,16 @@ class VersionUpgrade21to22(VersionUpgrade): return None return machine_instance.export() - ## Converts preferences from format version 1 to version 2. + ## Converts preferences from format version 2 to version 3. # - # \param serialised The serialised preferences file in version 1. - # \return The serialised preferences in version 2, or None if the input + # \param serialised The serialised preferences file in version 2. + # \return The serialised preferences in version 3, or None if the input # was not of the correct format. def upgradePreferences(self, serialised): - return serialised #TODO + preferences = Preferences.importFrom(serialised) + if not preferences: #Invalid file format. + return None + return preferences.export() ## Converts profiles from format version 1 to version 2. # From a5abfe29cdf78443e8c04f49ab061d1473947ebe Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Jun 2016 16:19:06 +0200 Subject: [PATCH 35/62] Fix call to translateSettingNames It's two modules deeper! Bit of weird magic due to how our plug-in import system works. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index f4c5e89b92..93c12116ef 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -51,7 +51,7 @@ class Preferences: visible_settings = self._config.get("machines", "setting_visibility") visible_settings = visible_settings.split(",") import VersionUpgrade21to22 #Import here to prevent a circular dependency. - visible_settings = VersionUpgrade21to22.translateSettingNames(visible_settings) + VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(visible_settings) visible_settings = visible_settings.join(",") self._config.set("machines", "setting_visibility", value = visible_settings) From 20d776c0d4d047b4beadc3e4a012ade99a46fd9a Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Jun 2016 16:21:14 +0200 Subject: [PATCH 36/62] Fix joining strings on comma The call worked a bit differently. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index 93c12116ef..87077b1fde 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -52,7 +52,7 @@ class Preferences: visible_settings = visible_settings.split(",") import VersionUpgrade21to22 #Import here to prevent a circular dependency. VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(visible_settings) - visible_settings = visible_settings.join(",") + visible_settings = ",".join(visible_settings) self._config.set("machines", "setting_visibility", value = visible_settings) #Update the version number itself. From 07b6507133a1c1ed142eb0c8718ee2264be9ab65 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 24 Jun 2016 16:52:04 +0200 Subject: [PATCH 37/62] Fix calls to translateSettings and translateSettingNames They are one module deeper, due to the way that plug-ins are imported by Uranium. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 +- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index ceb40fadd9..04bc8aefd5 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -74,7 +74,7 @@ class MachineInstance: config.set("general", "material", self._active_material_name) import VersionUpgrade21to22 # Import here to prevent circular dependencies. - VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) + VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) config.add_section("machine_settings") for key, value in self._machine_setting_overrides.items(): config.set("machine_settings", key, str(value)) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 15cc01c2ea..4d447e5587 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -93,19 +93,19 @@ class Profile: import VersionUpgrade21to22 # Import here to prevent circular dependencies. if self._settings: - VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) + VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) config.add_section("settings") for key, value in self._settings.items(): config.set("settings", key, str(value)) if self._changed_settings_defaults: - VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._changed_settings_defaults) + VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._changed_settings_defaults) config.add_section("defaults") for key, value in self._changed_settings_defaults.items(): config.set("defaults", key, str(value)) if self._disabled_settings_defaults: - VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(self._disabled_settings_defaults) + VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(self._disabled_settings_defaults) config.add_section("disabled_defaults") disabled_defaults_string = str(self._disabled_settings_defaults[0]) # Must be at least 1 item, otherwise we wouldn't enter this if statement. for item in self._disabled_settings_defaults[1:]: From 922b0df60bdb68e7871c90dd79df3d9108ea95a6 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 30 Jun 2016 14:21:07 +0200 Subject: [PATCH 38/62] Don't read machine instances as preferences Machine instances have the exact same file structure as preferences, except that machine instances require a name field (was already correctly implemented), but preferences didn't require it. This now forbids preferences to have a name field, so that the distinction between the two can be made. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index 87077b1fde..961f4f963e 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -35,6 +35,8 @@ class Preferences: raise UM.VersionUpgrade.FormatException("No \"version\" in \"general\" section.") if int(self._config.get("general", "version")) != 2: # Explicitly hard-code version 2, since if this number changes the programmer MUST change this entire function. raise UM.VersionUpgrade.InvalidVersionException("The version of this preferences file is wrong. It must be 2.") + if self._config.has_option("general", "name"): #This is probably a machine instance. + raise UM.VersionUpgrade.FormatException("There is a \"name\" field in this configuration file. I suspect it is not a preferences file.") ## Serialises these preferences as a preferences file of version 3. # From e1db3e5316ffac5a97d99586a5c08e0dee57335d Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 14:01:06 +0200 Subject: [PATCH 39/62] Convert instance profiles as profiles Treated in the same way. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 02207bbd50..50b6dcd48e 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -26,7 +26,7 @@ def getMetaData(): "sources": { "profile": { "get_version": upgrade.getCfgVersion, - "location": {"./profiles"} + "location": {"./profiles", "./instance_profiles"} }, "machine_instance": { "get_version": upgrade.getCfgVersion, From d1188899a7d4de87ad7bede251a22194be97d44e Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 14:38:51 +0200 Subject: [PATCH 40/62] Translate active machine setting It was in machines/active_instance. Now it's in cura/active_machine. The setting value remains the same. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index 961f4f963e..18391880e0 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -57,6 +57,12 @@ class Preferences: visible_settings = ",".join(visible_settings) self._config.set("machines", "setting_visibility", value = visible_settings) + #Translate the active_instance key. + if self._config.has_section("machines") and self._config.has_option("machines", "active_instance"): + active_machine = self._config.get("machines", "active_instance") + self._config.remove_option("machines", "active_instance") + self._config.set("cura", "active_machine", active_machine) + #Update the version number itself. self._config.set("general", "version", value = "3") From 2de811accfd94cb55d3b1da8eb85cf7392161f09 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 15:07:20 +0200 Subject: [PATCH 41/62] Update how machine instances are translated to stacks Lots of things have changed in how this works. Sadly, I can't translate things like the material, from PLA to ultimaker2_plus_0.4mm_pla. Not without implementing the entire container registry in the plug-in anyway. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 04bc8aefd5..84b38b9955 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -62,22 +62,26 @@ class MachineInstance: config.add_section("general") config.set("general", "name", self._name) + config.set("general", "id", self._name) config.set("general", "type", self._type_name) config.set("general", "version", "2") # Hard-code version 2, since if this number changes the programmer MUST change this entire function. - if self._variant_name: - config.set("general", "variant", self._variant_name) - if self._key: - config.set("general", "key", self._key) - if self._active_profile_name: - config.set("general", "active_profile", self._active_profile_name) - if self._active_material_name: - config.set("general", "material", self._active_material_name) + + containers = [] + containers.append(self._name + "_current_settings") + containers.append("empty") #The dependencies of the active profile, material and variant changed, so there is no 1:1 relation possible here. + containers.append("empty") + containers.append("empty") + containers.append(self._type_name) + config.set("general", "containers", ",".join(containers)) + + config.add_section("metadata") + config.set("metadata", "type", "machine") import VersionUpgrade21to22 # Import here to prevent circular dependencies. VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) - config.add_section("machine_settings") + config.add_section("values") for key, value in self._machine_setting_overrides.items(): - config.set("machine_settings", key, str(value)) + config.set("values", key, str(value)) output = io.StringIO() config.write(output) From fbffff4c8dd2a01110ab478180bb939371527b9b Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 15:28:35 +0200 Subject: [PATCH 42/62] Write list creation as literal Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 84b38b9955..b64e87f5b4 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -66,12 +66,13 @@ class MachineInstance: config.set("general", "type", self._type_name) config.set("general", "version", "2") # Hard-code version 2, since if this number changes the programmer MUST change this entire function. - containers = [] - containers.append(self._name + "_current_settings") - containers.append("empty") #The dependencies of the active profile, material and variant changed, so there is no 1:1 relation possible here. - containers.append("empty") - containers.append("empty") - containers.append(self._type_name) + containers = [ + self._name + "_current_settings", + "empty", #The dependencies of the active profile, material and variant changed, so there is no 1:1 relation possible here. + "empty", + "empty", + self._type_name + ] config.set("general", "containers", ",".join(containers)) config.add_section("metadata") From 28cc1e8cf7eebc1d4d8be6e406a564d83f272d4e Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 15:37:12 +0200 Subject: [PATCH 43/62] Translate material, variant and profile along They might not exist any more because the relation of profiles to printers changed from 2.1 to 2.2 for some machines (notably the UM2+ variants). But then it'll just make it empty when loading. Contributes to issue CURA-844. --- .../VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index b64e87f5b4..da58737d60 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -68,9 +68,9 @@ class MachineInstance: containers = [ self._name + "_current_settings", - "empty", #The dependencies of the active profile, material and variant changed, so there is no 1:1 relation possible here. - "empty", - "empty", + self._active_profile_name, + self._active_material_name, + self._variant_name, self._type_name ] config.set("general", "containers", ",".join(containers)) From 002f43598b8706e568b242e834c8127b46eb6e9e Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 16:48:18 +0200 Subject: [PATCH 44/62] Correct storing upgraded config location Two big things had to happen for this: The resource types of quality and machine stack have to be defined before the initialisation of the version upgrade manager, since the version upgrade manager needs to know those storage locations at initialisation. But the storage location is still prefaced with '.config/UM' at this point, so instead we pass on the resource type (but the resource type still has to be defined before the init). The other big change is that we now have to name the configuration type 'quality' and 'machine_stack' instead of 'instance_container' and 'container_stack' to coincide with the resource type. This allows us to be more consistent in later plug-ins when we also have to upgrade other instance container types. Contributes to issue CURA-844. --- cura/CuraApplication.py | 44 ++++++++++++------- .../VersionUpgrade21to22/__init__.py | 8 ++-- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 72d19d65a1..88ced6f68e 100644 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -19,7 +19,7 @@ from UM.JobQueue import JobQueue from UM.SaveFile import SaveFile from UM.Scene.Selection import Selection from UM.Scene.GroupDecorator import GroupDecorator -import UM.Settings.Validator +from UM.Settings.Validator import Validator from UM.Operations.AddSceneNodeOperation import AddSceneNodeOperation from UM.Operations.RemoveSceneNodeOperation import RemoveSceneNodeOperation @@ -99,7 +99,32 @@ class CuraApplication(QtApplication): SettingDefinition.addSupportedProperty("settable_per_extruder", DefinitionPropertyType.Any, default = True) SettingDefinition.addSupportedProperty("settable_per_meshgroup", DefinitionPropertyType.Any, default = True) SettingDefinition.addSupportedProperty("settable_globally", DefinitionPropertyType.Any, default = True) - SettingDefinition.addSettingType("extruder", int, str, UM.Settings.Validator) + SettingDefinition.addSettingType("extruder", int, str, Validator) + + ## Add the 4 types of profiles to storage. + Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality") + Resources.addStorageType(self.ResourceTypes.VariantInstanceContainer, "variants") + Resources.addStorageType(self.ResourceTypes.MaterialInstanceContainer, "materials") + Resources.addStorageType(self.ResourceTypes.UserInstanceContainer, "user") + Resources.addStorageType(self.ResourceTypes.ExtruderStack, "extruders") + Resources.addStorageType(self.ResourceTypes.MachineStack, "machine_instances") + + ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.QualityInstanceContainer) + ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.VariantInstanceContainer) + ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MaterialInstanceContainer) + ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.UserInstanceContainer) + ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.ExtruderStack) + ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MachineStack) + + ## Initialise the version upgrade manager with Cura's storage paths. + import UM.VersionUpgradeManager #Needs to be here to prevent circular dependencies. + self._version_upgrade_manager = UM.VersionUpgradeManager.VersionUpgradeManager( + { + ("quality", UM.Settings.InstanceContainer.Version): (self.ResourceTypes.QualityInstanceContainer, "application/x-uranium-instancecontainer"), + ("machine_stack", UM.Settings.ContainerStack.Version): (self.ResourceTypes.MachineStack, "application/x-uranium-containerstack"), + ("preferences", UM.Preferences.Version): (Resources.Preferences, "application/x-uranium-preferences") + } + ) self._machine_action_manager = MachineActionManager.MachineActionManager() @@ -142,21 +167,6 @@ class CuraApplication(QtApplication): self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading machines...")) - ## Add the 4 types of profiles to storage. - Resources.addStorageType(self.ResourceTypes.QualityInstanceContainer, "quality") - Resources.addStorageType(self.ResourceTypes.VariantInstanceContainer, "variants") - Resources.addStorageType(self.ResourceTypes.MaterialInstanceContainer, "materials") - Resources.addStorageType(self.ResourceTypes.UserInstanceContainer, "user") - Resources.addStorageType(self.ResourceTypes.ExtruderStack, "extruders") - Resources.addStorageType(self.ResourceTypes.MachineStack, "machine_instances") - - ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.QualityInstanceContainer) - ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.VariantInstanceContainer) - ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MaterialInstanceContainer) - ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.UserInstanceContainer) - ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.ExtruderStack) - ContainerRegistry.getInstance().addResourceType(self.ResourceTypes.MachineStack) - # Add empty variant, material and quality containers. # Since they are empty, they should never be serialized and instead just programmatically created. # We need them to simplify the switching between materials. diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py index 50b6dcd48e..86cfda6b90 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/__init__.py @@ -18,10 +18,10 @@ def getMetaData(): "api": 3 }, "version_upgrade": { - # From To Upgrade function - ("profile", 1): ("instance_container", 2, upgrade.upgradeProfile), - ("machine_instance", 1): ("container_stack", 2, upgrade.upgradeMachineInstance), - ("preferences", 2): ("preferences", 3, upgrade.upgradePreferences) + # From To Upgrade function + ("profile", 1): ("quality", 2, upgrade.upgradeProfile), + ("machine_instance", 1): ("machine_stack", 2, upgrade.upgradeMachineInstance), + ("preferences", 2): ("preferences", 3, upgrade.upgradePreferences) }, "sources": { "profile": { From 7f5b656c68000c31985d8783650d60b2aa3b7a11 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 17:17:57 +0200 Subject: [PATCH 45/62] Update translation of metadata A few fields are different now. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 4d447e5587..4383b50f4e 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -83,11 +83,11 @@ class Profile: if self._weight: config.set("general", "weight", self._weight) if self._machine_type_id: - config.set("general", "machine_type", self._machine_type_id) + config.set("general", "definition", self._machine_type_id) + else: + config.set("general", "definition", "fdmprinter") if self._machine_variant_name: - config.set("general", "machine_variant", self._machine_variant_name) - if self._machine_instance_name: - config.set("general", "machine_instance", self._machine_instance_name) + config.set("general", "variant", self._machine_variant_name) if self._material_name and self._type != "material": config.set("general", "material", self._material_name) From a87e756a42998ad378c249860623af16e6e7078d Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 17:25:33 +0200 Subject: [PATCH 46/62] Translate machine names Some names might be changed. I know of at least one: ultimaker2plus -> ultimaker2_plus. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 3 ++- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 4383b50f4e..d5f38585c9 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -83,7 +83,8 @@ class Profile: if self._weight: config.set("general", "weight", self._weight) if self._machine_type_id: - config.set("general", "definition", self._machine_type_id) + translated_machine = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinters([self._machine_type_id])[0] + config.set("general", "definition", translated_machine) else: config.set("general", "definition", "fdmprinter") if self._machine_variant_name: diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index a06369f301..8a166ba160 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -58,6 +58,12 @@ class VersionUpgrade21to22(VersionUpgrade): return None return profile.export() + @staticmethod + def translatePrinters(printers): + for index, printer in enumerate(printers): + if printer == "ultimaker2plus": + printers[index] = "ultimaker2_plus" + ## Updates settings for the change from Cura 2.1 to 2.2. # # The keys and values of settings are changed to what they should be in From 39212a601e408df59750bea859c7cef6b4a40e69 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 17:35:52 +0200 Subject: [PATCH 47/62] Fix import Didn't see this due to the sea of errors that it gives. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index d5f38585c9..ce6bac4c40 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -73,6 +73,8 @@ class Profile: # \return A serialised form of this profile, serialised in version 2 of # the file format. def export(self): + import VersionUpgrade21to22 # Import here to prevent circular dependencies. + config = configparser.ConfigParser(interpolation = None) config.add_section("general") @@ -92,7 +94,6 @@ class Profile: if self._material_name and self._type != "material": config.set("general", "material", self._material_name) - import VersionUpgrade21to22 # Import here to prevent circular dependencies. if self._settings: VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) config.add_section("settings") From 86544d41726359ae8d8166f6cd1a4ea06d8fc471 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 19:02:35 +0200 Subject: [PATCH 48/62] Fix translate function It was expected to return a list of translated names, even though it actually translates in-place. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 8a166ba160..f54609256d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -58,11 +58,16 @@ class VersionUpgrade21to22(VersionUpgrade): return None return profile.export() + ## Translates printer names that have changed since the last version. + # + # \param printers A list of printer names in the old version. + # \return The same list, but with printer names translated. @staticmethod def translatePrinters(printers): for index, printer in enumerate(printers): if printer == "ultimaker2plus": printers[index] = "ultimaker2_plus" + return printers ## Updates settings for the change from Cura 2.1 to 2.2. # From 7939a03114f006b2fb439b2b42a4a08bb0cf1076 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 1 Jul 2016 19:05:19 +0200 Subject: [PATCH 49/62] Fix translating current_settings It is not entirely accurate in the translated version, since the new current_settings is not machine-dependent any more. However, without information on the original file name, this is as good as it gets, since that instance profile there only mentions the machine it is dependent on in the file name. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index da58737d60..894e9a8c7a 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -67,7 +67,7 @@ class MachineInstance: config.set("general", "version", "2") # Hard-code version 2, since if this number changes the programmer MUST change this entire function. containers = [ - self._name + "_current_settings", + self._name, self._active_profile_name, self._active_material_name, self._variant_name, From f07598a2287fc809a03bbd0878a58141fa1ffeff Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sun, 3 Jul 2016 23:21:43 +0200 Subject: [PATCH 50/62] Translate profile names too Not all profile name translations are entered yet, I think. I just did the material ones. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 8 +++++--- .../VersionUpgrade21to22.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 894e9a8c7a..7582befca6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -66,10 +66,13 @@ class MachineInstance: config.set("general", "type", self._type_name) config.set("general", "version", "2") # Hard-code version 2, since if this number changes the programmer MUST change this entire function. + import VersionUpgrade21to22 # Import here to prevent circular dependencies. + active_profile = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name) + active_material = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_material_name) containers = [ self._name, - self._active_profile_name, - self._active_material_name, + active_profile, + active_material, self._variant_name, self._type_name ] @@ -78,7 +81,6 @@ class MachineInstance: config.add_section("metadata") config.set("metadata", "type", "machine") - import VersionUpgrade21to22 # Import here to prevent circular dependencies. VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._machine_setting_overrides) config.add_section("values") for key, value in self._machine_setting_overrides.items(): diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index f54609256d..641931c5a4 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -9,6 +9,13 @@ from . import MachineInstance # To upgrade machine instances. from . import Preferences #To upgrade preferences. from . import Profile # To upgrade profiles. +## How to translate profile names from the old version to the new. +_profile_translation = { + "PLA": "generic_pla", + "ABS": "generic_abs", + "CPE": "generic_cpe" +} + ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. # # It converts the machine instances and profiles. @@ -69,6 +76,17 @@ class VersionUpgrade21to22(VersionUpgrade): printers[index] = "ultimaker2_plus" return printers + ## Translates a built-in profile name that might have changed since the + # last version. + # + # \param profile A profile name in the old version. + # \return The corresponding profile name in the new version. + @staticmethod + def translateProfile(profile): + if profile in _profile_translation: + return _profile_translation[profile] + return profile + ## Updates settings for the change from Cura 2.1 to 2.2. # # The keys and values of settings are changed to what they should be in From 88b36ad3d7b837dc63590831cddecccd7cf07b21 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sun, 3 Jul 2016 23:31:10 +0200 Subject: [PATCH 51/62] Make translateSettingName use dictionary look-up This solution is a bit neater in code. It makes the function perform a single purpose, since it no longer translates a list of setting names but just one. Also it now neatly puts the translations in a separate, easy-to-modify dict. Only disadvantage is when simple key look-up is not sufficient, such as when renaming lots of settings at once, where substring matching would make the code a bit shorter. But we shouldn't do such a rename anyway. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/Preferences.py | 3 ++- .../VersionUpgrade21to22.py | 24 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index 18391880e0..37cb3ccb9f 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -53,7 +53,8 @@ class Preferences: visible_settings = self._config.get("machines", "setting_visibility") visible_settings = visible_settings.split(",") import VersionUpgrade21to22 #Import here to prevent a circular dependency. - VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(visible_settings) + visible_settings = [VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingName(setting_name) + for setting_name in visible_settings] visible_settings = ",".join(visible_settings) self._config.set("machines", "setting_visibility", value = visible_settings) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 641931c5a4..e1632e0d85 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -16,6 +16,10 @@ _profile_translation = { "CPE": "generic_cpe" } +_setting_name_translation = { + "speed_support_lines": "speed_support_infill" +} + ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. # # It converts the machine instances and profiles. @@ -85,7 +89,7 @@ class VersionUpgrade21to22(VersionUpgrade): def translateProfile(profile): if profile in _profile_translation: return _profile_translation[profile] - return profile + return profile #Doesn't need to be translated. ## Updates settings for the change from Cura 2.1 to 2.2. # @@ -105,16 +109,12 @@ class VersionUpgrade21to22(VersionUpgrade): settings[key] = "off" if (value == "False") else "all" return settings - ## Translates setting names for the change from Cura 2.1 to 2.2. + ## Translates a setting name for the change from Cura 2.1 to 2.2. # - # The setting names are changed in-place in the provided list. This changes - # the input parameter. - # - # \param settings A list of setting names to update. - # \return The same list. + # \param setting The name of a setting in Cura 2.1. + # \return The name of the corresponding setting in Cura 2.2. @staticmethod - def translateSettingNames(settings): - for i in range(0, len(settings)): - if settings[i] == "speed_support_lines": - settings[i] = "speed_support_infill" - return settings \ No newline at end of file + def translateSettingName(setting): + if setting in _setting_name_translation: + return _setting_name_translation[setting] + return setting #Doesn't need to be translated. \ No newline at end of file From b5efb2eee846616d2d822c7325601b5ca83f8431 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sun, 3 Jul 2016 23:37:11 +0200 Subject: [PATCH 52/62] Make profile translation use new translateSettingName Forgot about this one. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index ce6bac4c40..3f49a3862d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -107,10 +107,11 @@ class Profile: config.set("defaults", key, str(value)) if self._disabled_settings_defaults: - VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingNames(self._disabled_settings_defaults) + disabled_settings_defaults = [VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingName(setting) + for setting in self._disabled_settings_defaults] config.add_section("disabled_defaults") - disabled_defaults_string = str(self._disabled_settings_defaults[0]) # Must be at least 1 item, otherwise we wouldn't enter this if statement. - for item in self._disabled_settings_defaults[1:]: + disabled_defaults_string = str(disabled_settings_defaults[0]) # Must be at least 1 item, otherwise we wouldn't enter this if statement. + for item in disabled_settings_defaults[1:]: disabled_defaults_string += "," + str(item) output = io.StringIO() From f13db7de108b53320bbde9382a4d95e0c2311a1e Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Sun, 3 Jul 2016 23:58:38 +0200 Subject: [PATCH 53/62] Make translatePrinter use dict A translation dictionary makes it much easier to edit the translations. Also this now just translates one printer, instead of a list. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/Profile.py | 2 +- .../VersionUpgrade21to22.py | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 3f49a3862d..f194fe8101 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -85,7 +85,7 @@ class Profile: if self._weight: config.set("general", "weight", self._weight) if self._machine_type_id: - translated_machine = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinters([self._machine_type_id])[0] + translated_machine = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinter(self._machine_type_id) config.set("general", "definition", translated_machine) else: config.set("general", "definition", "fdmprinter") diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index e1632e0d85..71e5f9efbe 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -9,6 +9,11 @@ from . import MachineInstance # To upgrade machine instances. from . import Preferences #To upgrade preferences. from . import Profile # To upgrade profiles. +## How to translate printer names from the old version to the new. +_printer_translation = { + "ultimaker2plus": "ultimaker2_plus" +} + ## How to translate profile names from the old version to the new. _profile_translation = { "PLA": "generic_pla", @@ -16,6 +21,7 @@ _profile_translation = { "CPE": "generic_cpe" } +## How to translate setting names from the old version to the new. _setting_name_translation = { "speed_support_lines": "speed_support_infill" } @@ -69,16 +75,16 @@ class VersionUpgrade21to22(VersionUpgrade): return None return profile.export() - ## Translates printer names that have changed since the last version. + ## Translates a printer name that might have changed since the last + # version. # - # \param printers A list of printer names in the old version. - # \return The same list, but with printer names translated. + # \param printer A printer name in Cura 2.1. + # \return The name of the corresponding printer in Cura 2.2. @staticmethod - def translatePrinters(printers): - for index, printer in enumerate(printers): - if printer == "ultimaker2plus": - printers[index] = "ultimaker2_plus" - return printers + def translatePrinter(printer): + if printer in _printer_translation: + return _printer_translation[printer] + return printer #Doesn't need to be translated. ## Translates a built-in profile name that might have changed since the # last version. From 439629d0b51f1cedea337cb4058d99df8d2cbf8e Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 4 Jul 2016 00:11:51 +0200 Subject: [PATCH 54/62] Translate variants and machine names I'm not quite pleased with the variant translation being inside this function, so I'll move it to VersionUpgrade21to22 soon I think. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 7582befca6..63e853d649 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -67,14 +67,40 @@ class MachineInstance: config.set("general", "version", "2") # Hard-code version 2, since if this number changes the programmer MUST change this entire function. import VersionUpgrade21to22 # Import here to prevent circular dependencies. + type_name = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinter(self._type_name) active_profile = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name) active_material = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_material_name) + if type_name == "ultimaker2_plus": + if self._variant_name == "0.25 mm": + variant = "ultimaker2_plus_0.25" + elif self._variant_name == "0.4 mm": + variant = "ultimaker2_plus_0.4" + elif self._variant_name == "0.6 mm": + variant = "ultimaker2_plus_0.6" + elif self._variant_name == "0.8 mm": + variant = "ultimaker2_plus_0.8" + else: + variant = self._variant_name + elif type_name == "ultimaker2_extended_plus": + if self._variant_name == "0.25 mm": + variant = "ultimaker2_extended_plus_0.25" + elif self._variant_name == "0.4 mm": + variant = "ultimaker2_extended_plus_0.4" + elif self._variant_name == "0.6 mm": + variant = "ultimaker2_extended_plus_0.6" + elif self._variant_name == "0.8 mm": + variant = "ultimaker2_extended_plus_0.8" + else: + variant = self._variant_name + else: + variant = self._variant_name + containers = [ self._name, active_profile, active_material, - self._variant_name, - self._type_name + variant, + type_name ] config.set("general", "containers", ",".join(containers)) From 93041191c25dcf9af9c29b3869080fcdac3df58d Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 4 Jul 2016 00:18:52 +0200 Subject: [PATCH 55/62] Move translateVariant to VersionUpgrade21to22 Also make it a dictionary look-up, like the rest, instead of a series of if-statements. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 25 +-------------- .../VersionUpgrade21to22.py | 31 ++++++++++++++++++- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 63e853d649..98545969cd 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -70,30 +70,7 @@ class MachineInstance: type_name = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinter(self._type_name) active_profile = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_profile_name) active_material = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateProfile(self._active_material_name) - if type_name == "ultimaker2_plus": - if self._variant_name == "0.25 mm": - variant = "ultimaker2_plus_0.25" - elif self._variant_name == "0.4 mm": - variant = "ultimaker2_plus_0.4" - elif self._variant_name == "0.6 mm": - variant = "ultimaker2_plus_0.6" - elif self._variant_name == "0.8 mm": - variant = "ultimaker2_plus_0.8" - else: - variant = self._variant_name - elif type_name == "ultimaker2_extended_plus": - if self._variant_name == "0.25 mm": - variant = "ultimaker2_extended_plus_0.25" - elif self._variant_name == "0.4 mm": - variant = "ultimaker2_extended_plus_0.4" - elif self._variant_name == "0.6 mm": - variant = "ultimaker2_extended_plus_0.6" - elif self._variant_name == "0.8 mm": - variant = "ultimaker2_extended_plus_0.8" - else: - variant = self._variant_name - else: - variant = self._variant_name + variant = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(self._variant_name, type_name) containers = [ self._name, diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 71e5f9efbe..a1761a7498 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -26,6 +26,23 @@ _setting_name_translation = { "speed_support_lines": "speed_support_infill" } +## How to translate variants of specific machines from the old version to the +# new. +_variant_translation = { + "ultimaker2_plus": { + "0.25 mm": "ultimaker2_plus_0.25", + "0.4 mm": "ultimaker2_plus_0.4", + "0.6 mm": "ultimaker2_plus_0.6", + "0.8 mm": "ultimaker2_plus_0.8" + }, + "ultimaker2_extended_plus": { + "0.25 mm": "ultimaker2_extended_plus_0.25", + "0.4 mm": "ultimaker2_extended_plus_0.4", + "0.6 mm": "ultimaker2_extended_plus_0.6", + "0.8 mm": "ultimaker2_extended_plus_0.8" + } +} + ## Converts configuration from Cura 2.1's file formats to Cura 2.2's. # # It converts the machine instances and profiles. @@ -123,4 +140,16 @@ class VersionUpgrade21to22(VersionUpgrade): def translateSettingName(setting): if setting in _setting_name_translation: return _setting_name_translation[setting] - return setting #Doesn't need to be translated. \ No newline at end of file + return setting #Doesn't need to be translated. + + ## Translates a variant name for the change from Cura 2.1 to 2.2 + # + # \param variant The name of a variant in Cura 2.1. + # \param machine The name of the machine this variant is part of in Cura + # 2.2's naming. + # \return The name of the corresponding variant in Cura 2.2. + @staticmethod + def translateVariant(variant, machine): + if machine in _variant_translation and variant in _variant_translation[machine]: + return _variant_translation[machine][variant] + return variant \ No newline at end of file From c50619e3631dc9878d83edd2f26ce28498895ab4 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 4 Jul 2016 01:08:24 +0200 Subject: [PATCH 56/62] Add additional settings transformations since 2.1 These should be all the settings that were changed since Cura 2.1. Contributes to issue CURA-844. --- .../VersionUpgrade21to22.py | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index a1761a7498..4f7d43b5c6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -23,6 +23,10 @@ _profile_translation = { ## How to translate setting names from the old version to the new. _setting_name_translation = { + "remove_overlapping_walls_0_enabled": "travel_compensate_overlapping_walls_0_enabled", + "remove_overlapping_walls_enabled": "travel_compensate_overlapping_walls_enabled", + "remove_overlapping_walls_x_enabled": "travel_compensate_overlapping_walls_x_enabled", + "retraction_hop": "retraction_hop_enabled", "speed_support_lines": "speed_support_infill" } @@ -125,11 +129,25 @@ class VersionUpgrade21to22(VersionUpgrade): @staticmethod def translateSettings(settings): for key, value in settings.items(): - if key == "speed_support_lines": # Setting key was changed for 2.2. + if key == "fill_perimeter_gaps": #Setting is removed. + del settings[key] + elif key == "remove_overlapping_walls_0_enabled": #Setting is functionally replaced. + del settings[key] + settings["travel_compensate_overlapping_walls_0_enabled"] = value + elif key == "remove_overlapping_walls_enabled": #Setting is functionally replaced. + del settings[key] + settings["travel_compensate_overlapping_walls_enabled"] = value + elif key == "remove_overlapping_walls_x_enabled": #Setting is functionally replaced. + del settings[key] + settings["travel_compensate_overlapping_walls_x_enabled"] = value + elif key == "retraction_combing": #Combing was made into an enum instead of a boolean. + settings[key] = "off" if (value == "False") else "all" + elif key == "retraction_hop": #Setting key was changed. + del settings[key] + settings["retraction_hop_enabled"] = value + elif key == "speed_support_lines": #Setting key was changed. del settings[key] settings["speed_support_infill"] = value - if key == "retraction_combing": # Combing was made into an enum instead of a boolean. - settings[key] = "off" if (value == "False") else "all" return settings ## Translates a setting name for the change from Cura 2.1 to 2.2. From b841738b76a1e38e3e8971ac86b6df4552c7d44b Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 4 Jul 2016 01:18:26 +0200 Subject: [PATCH 57/62] Translate variants in profile Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index f194fe8101..915ecceec6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -78,7 +78,7 @@ class Profile: config = configparser.ConfigParser(interpolation = None) config.add_section("general") - config.set("general", "version", "2") # Hard-coded profile version 2 + config.set("general", "version", "2") #Hard-coded profile version 2. config.set("general", "name", self._name) if self._type: config.set("general", "type", self._type) @@ -90,7 +90,10 @@ class Profile: else: config.set("general", "definition", "fdmprinter") if self._machine_variant_name: - config.set("general", "variant", self._machine_variant_name) + if self._machine_type_id: + config.set("general", "variant", VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(self._machine_variant_name, self._machine_type_id)) + else: + config.set("general", "variant", self._machine_variant_name) if self._material_name and self._type != "material": config.set("general", "material", self._material_name) @@ -110,7 +113,7 @@ class Profile: disabled_settings_defaults = [VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettingName(setting) for setting in self._disabled_settings_defaults] config.add_section("disabled_defaults") - disabled_defaults_string = str(disabled_settings_defaults[0]) # Must be at least 1 item, otherwise we wouldn't enter this if statement. + disabled_defaults_string = str(disabled_settings_defaults[0]) #Must be at least 1 item, otherwise we wouldn't enter this if statement. for item in disabled_settings_defaults[1:]: disabled_defaults_string += "," + str(item) From 8f34186a9b491070321f06896e12d67faf20a2d1 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 4 Jul 2016 01:27:13 +0200 Subject: [PATCH 58/62] Rename settings section to values It should be called 'values' in the new version. Contributes to issue CURA-844. --- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 915ecceec6..9ebf415f78 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -99,9 +99,9 @@ class Profile: if self._settings: VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) - config.add_section("settings") + config.add_section("values") for key, value in self._settings.items(): - config.set("settings", key, str(value)) + config.set("values", key, str(value)) if self._changed_settings_defaults: VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._changed_settings_defaults) From 19b4ec655efb87dd71aa82a99916954208cc8a85 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Mon, 4 Jul 2016 01:36:48 +0200 Subject: [PATCH 59/62] Move some things to metadata section Why there is a difference between 'general' and 'metadata', only His Noodleness knows. Also put in a default for the type. It should apparently be 'quality' unless it is a user profile. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/Profile.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 9ebf415f78..1b2f90d917 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -80,22 +80,26 @@ class Profile: config.add_section("general") config.set("general", "version", "2") #Hard-coded profile version 2. config.set("general", "name", self._name) - if self._type: - config.set("general", "type", self._type) - if self._weight: - config.set("general", "weight", self._weight) if self._machine_type_id: translated_machine = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translatePrinter(self._machine_type_id) config.set("general", "definition", translated_machine) else: config.set("general", "definition", "fdmprinter") + + config.add_section("metadata") + if self._type: + config.set("metadata", "type", self._type) + else: + config.set("metadata", "type", "quality") + if self._weight: + config.set("metadata", "weight", self._weight) if self._machine_variant_name: if self._machine_type_id: - config.set("general", "variant", VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(self._machine_variant_name, self._machine_type_id)) + config.set("metadata", "variant", VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(self._machine_variant_name, self._machine_type_id)) else: - config.set("general", "variant", self._machine_variant_name) + config.set("metadata", "variant", self._machine_variant_name) if self._material_name and self._type != "material": - config.set("general", "material", self._material_name) + config.set("metadata", "material", self._material_name) if self._settings: VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateSettings(self._settings) From 1b0974ba9f862942d58d6b7b655d4a4815d4b033 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 5 Jul 2016 09:54:39 +0200 Subject: [PATCH 60/62] Rename translation dicts to plural form This is more in line with the rest of the code. Contributes to issue CURA-844. --- .../VersionUpgrade21to22.py | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index 4f7d43b5c6..e798517e15 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -10,19 +10,19 @@ from . import Preferences #To upgrade preferences. from . import Profile # To upgrade profiles. ## How to translate printer names from the old version to the new. -_printer_translation = { +_printer_translations = { "ultimaker2plus": "ultimaker2_plus" } ## How to translate profile names from the old version to the new. -_profile_translation = { +_profile_translations = { "PLA": "generic_pla", "ABS": "generic_abs", "CPE": "generic_cpe" } ## How to translate setting names from the old version to the new. -_setting_name_translation = { +_setting_name_translations = { "remove_overlapping_walls_0_enabled": "travel_compensate_overlapping_walls_0_enabled", "remove_overlapping_walls_enabled": "travel_compensate_overlapping_walls_enabled", "remove_overlapping_walls_x_enabled": "travel_compensate_overlapping_walls_x_enabled", @@ -32,7 +32,7 @@ _setting_name_translation = { ## How to translate variants of specific machines from the old version to the # new. -_variant_translation = { +_variant_translations = { "ultimaker2_plus": { "0.25 mm": "ultimaker2_plus_0.25", "0.4 mm": "ultimaker2_plus_0.4", @@ -103,8 +103,8 @@ class VersionUpgrade21to22(VersionUpgrade): # \return The name of the corresponding printer in Cura 2.2. @staticmethod def translatePrinter(printer): - if printer in _printer_translation: - return _printer_translation[printer] + if printer in _printer_translations: + return _printer_translations[printer] return printer #Doesn't need to be translated. ## Translates a built-in profile name that might have changed since the @@ -114,8 +114,8 @@ class VersionUpgrade21to22(VersionUpgrade): # \return The corresponding profile name in the new version. @staticmethod def translateProfile(profile): - if profile in _profile_translation: - return _profile_translation[profile] + if profile in _profile_translations: + return _profile_translations[profile] return profile #Doesn't need to be translated. ## Updates settings for the change from Cura 2.1 to 2.2. @@ -156,8 +156,8 @@ class VersionUpgrade21to22(VersionUpgrade): # \return The name of the corresponding setting in Cura 2.2. @staticmethod def translateSettingName(setting): - if setting in _setting_name_translation: - return _setting_name_translation[setting] + if setting in _setting_name_translations: + return _setting_name_translations[setting] return setting #Doesn't need to be translated. ## Translates a variant name for the change from Cura 2.1 to 2.2 @@ -168,6 +168,6 @@ class VersionUpgrade21to22(VersionUpgrade): # \return The name of the corresponding variant in Cura 2.2. @staticmethod def translateVariant(variant, machine): - if machine in _variant_translation and variant in _variant_translation[machine]: - return _variant_translation[machine][variant] + if machine in _variant_translations and variant in _variant_translations[machine]: + return _variant_translations[machine][variant] return variant \ No newline at end of file From e6efba38687ed9f0b7253a6d8f3b95799de8a5d7 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 7 Jul 2016 15:13:58 +0200 Subject: [PATCH 61/62] Make version upgrade also translate file names This was required since Cura 2.1 produced files with the same filename (bar extension). This then resulted in two containers with the same ID. If you had bad luck, an instance container was chosen as global container (depending on which was first in the unordered dictionary). This gives the current settings the postfix _current_settings, fixing that issue. Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 18 ++++++---- .../VersionUpgrade21to22/Preferences.py | 15 +++++--- .../VersionUpgrade21to22/Profile.py | 21 +++++++---- .../VersionUpgrade21to22.py | 35 +++++++++++-------- 4 files changed, 55 insertions(+), 34 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 98545969cd..46003d4d21 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -10,11 +10,12 @@ import io #To write config files to strings as if they were files. # instance in version 1 of the file format. # # \param serialised The serialised form of a machine instance in version 1. +# \param filename The supposed file name of this machine instance. # \return A machine instance instance, or None if the file format is # incorrect. -def importFrom(serialised): +def importFrom(serialised, filename): try: - return MachineInstance(serialised) + return MachineInstance(serialised, filename) except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException): return None @@ -24,7 +25,10 @@ class MachineInstance: ## Reads version 1 of the file format, storing it in memory. # # \param serialised A string with the contents of a machine instance file. - def __init__(self, serialised): + # \param filename The supposed file name of this machine instance. + def __init__(self, serialised, filename): + self._filename = filename + config = configparser.ConfigParser(interpolation = None) config.read_string(serialised) # Read the input string as config file. @@ -55,8 +59,8 @@ class MachineInstance: # # This is where the actual translation happens in this case. # - # \return A serialised form of this machine instance, serialised in - # version 2 of the file format. + # \return A tuple containing the new filename and a serialised form of + # this machine instance, serialised in version 2 of the file format. def export(self): config = configparser.ConfigParser(interpolation = None) # Build a config file in the form of version 2. @@ -73,7 +77,7 @@ class MachineInstance: variant = VersionUpgrade21to22.VersionUpgrade21to22.VersionUpgrade21to22.translateVariant(self._variant_name, type_name) containers = [ - self._name, + self._name + "_current_settings", active_profile, active_material, variant, @@ -91,4 +95,4 @@ class MachineInstance: output = io.StringIO() config.write(output) - return output.getvalue() \ No newline at end of file + return self._filename, output.getvalue() \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index 37cb3ccb9f..2fcacedbf6 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -10,11 +10,12 @@ import UM.VersionUpgrade #To indicate that a file is of the wrong format. # in version 1 of the file format. # # \param serialised The serialised form of a preferences file in version 1. +# \param filename The supposed filename of the preferences file. # \return A representation of those preferences, or None if the file format is # incorrect. -def importFrom(serialised): +def importFrom(serialised, filename): try: - return Preferences(serialised) + return Preferences(serialised, filename) except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException): return None @@ -24,7 +25,10 @@ class Preferences: ## Reads version 2 of the preferences file format, storing it in memory. # # \param serialised A serialised version 2 preferences file. - def __init__(self, serialised): + # \param filename The supposed filename of the preferences file. + def __init__(self, serialised, filename): + self._filename = filename + self._config = configparser.ConfigParser(interpolation = None) self._config.read_string(serialised) @@ -42,7 +46,8 @@ class Preferences: # # This is where the actual translation happens. # - # \return A serialised version of a preferences file in version 3. + # \return A tuple containing the new filename and a serialised version of + # a preferences file in version 3. def export(self): #Reset the cura/categories_expanded property since it works differently now. if self._config.has_section("cura") and self._config.has_option("cura", "categories_expanded"): @@ -70,4 +75,4 @@ class Preferences: #Output the result as a string. output = io.StringIO() self._config.write(output) - return output.getvalue() \ No newline at end of file + return self._filename, output.getvalue() \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 1b2f90d917..2f911d755d 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -10,10 +10,11 @@ import UM.VersionUpgrade # of the file format. # # \param serialised The serialised form of a profile in version 1. +# \param filename The supposed filename of the profile. # \return A profile instance, or None if the file format is incorrect. -def importFrom(serialised): +def importFrom(serialised, filename): try: - return Profile(serialised) + return Profile(serialised, filename) except (configparser.Error, UM.VersionUpgrade.FormatException, UM.VersionUpgrade.InvalidVersionException): return None @@ -22,8 +23,11 @@ def importFrom(serialised): class Profile: ## Reads version 1 of the file format, storing it in memory. # - # \param serialised A string with the contents of a machine instance file. - def __init__(self, serialised): + # \param serialised A string with the contents of a profile. + # \param filename The supposed filename of the profile. + def __init__(self, serialised, filename): + self._filename = filename + parser = configparser.ConfigParser(interpolation = None) parser.read_string(serialised) @@ -70,11 +74,14 @@ class Profile: ## Serialises this profile as file format version 2. # - # \return A serialised form of this profile, serialised in version 2 of - # the file format. + # \return A tuple containing the new filename and a serialised form of + # this profile, serialised in version 2 of the file format. def export(self): import VersionUpgrade21to22 # Import here to prevent circular dependencies. + if self._name == "Current settings": + self._filename += "_current_settings" #This resolves a duplicate ID arising from how Cura 2.1 stores its current settings. + config = configparser.ConfigParser(interpolation = None) config.add_section("general") @@ -123,4 +130,4 @@ class Profile: output = io.StringIO() config.write(output) - return output.getvalue() \ No newline at end of file + return self._filename, output.getvalue() \ No newline at end of file diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index e798517e15..ae2356d720 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -66,34 +66,39 @@ class VersionUpgrade21to22(VersionUpgrade): ## Converts machine instances from format version 1 to version 2. # # \param serialised The serialised machine instance in version 1. - # \return The serialised machine instance in version 2, or None if the - # input was not of the correct format. - def upgradeMachineInstance(self, serialised): - machine_instance = MachineInstance.importFrom(serialised) + # \param filename The supposed file name of the machine instance. + # \return A tuple containing the new filename and the serialised machine + # instance in version 2, or None if the input was not of the correct + # format. + def upgradeMachineInstance(self, serialised, filename): + machine_instance = MachineInstance.importFrom(serialised, filename) if not machine_instance: #Invalid file format. - return None + return filename, None return machine_instance.export() ## Converts preferences from format version 2 to version 3. # # \param serialised The serialised preferences file in version 2. - # \return The serialised preferences in version 3, or None if the input - # was not of the correct format. - def upgradePreferences(self, serialised): - preferences = Preferences.importFrom(serialised) + # \param filename THe supposed file name of the preferences file. + # \return A tuple containing the new filename and the serialised + # preferences in version 3, or None if the input was not of the correct + # format. + def upgradePreferences(self, serialised, filename): + preferences = Preferences.importFrom(serialised, filename) if not preferences: #Invalid file format. - return None + return filename, None return preferences.export() ## Converts profiles from format version 1 to version 2. # # \param serialised The serialised profile in version 1. - # \return The serialised profile in version 2, or None if the input was - # not of the correct format. - def upgradeProfile(self, serialised): - profile = Profile.importFrom(serialised) + # \param filename The supposed file name of the profile. + # \return A tuple containing the new filename and the serialised profile + # in version 2, or None if the input was not of the correct format. + def upgradeProfile(self, serialised, filename): + profile = Profile.importFrom(serialised, filename) if not profile: # Invalid file format. - return None + return filename, None return profile.export() ## Translates a printer name that might have changed since the last From 8f5e56c66ec39502b569c20e147ff93fba006d9c Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 7 Jul 2016 15:22:27 +0200 Subject: [PATCH 62/62] Make documentation specify filename without extension Contributes to issue CURA-844. --- .../VersionUpgrade21to22/MachineInstance.py | 6 ++++-- .../VersionUpgrade/VersionUpgrade21to22/Preferences.py | 6 ++++-- plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py | 4 ++-- .../VersionUpgrade21to22/VersionUpgrade21to22.py | 9 ++++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py index 46003d4d21..a7534dc862 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/MachineInstance.py @@ -10,7 +10,8 @@ import io #To write config files to strings as if they were files. # instance in version 1 of the file format. # # \param serialised The serialised form of a machine instance in version 1. -# \param filename The supposed file name of this machine instance. +# \param filename The supposed file name of this machine instance, without +# extension. # \return A machine instance instance, or None if the file format is # incorrect. def importFrom(serialised, filename): @@ -24,7 +25,8 @@ def importFrom(serialised, filename): class MachineInstance: ## Reads version 1 of the file format, storing it in memory. # - # \param serialised A string with the contents of a machine instance file. + # \param serialised A string with the contents of a machine instance file, + # without extension. # \param filename The supposed file name of this machine instance. def __init__(self, serialised, filename): self._filename = filename diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py index 2fcacedbf6..9f6a36d87a 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Preferences.py @@ -10,7 +10,8 @@ import UM.VersionUpgrade #To indicate that a file is of the wrong format. # in version 1 of the file format. # # \param serialised The serialised form of a preferences file in version 1. -# \param filename The supposed filename of the preferences file. +# \param filename The supposed filename of the preferences file, without +# extension. # \return A representation of those preferences, or None if the file format is # incorrect. def importFrom(serialised, filename): @@ -25,7 +26,8 @@ class Preferences: ## Reads version 2 of the preferences file format, storing it in memory. # # \param serialised A serialised version 2 preferences file. - # \param filename The supposed filename of the preferences file. + # \param filename The supposed filename of the preferences file, without + # extension. def __init__(self, serialised, filename): self._filename = filename diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 2f911d755d..621f346887 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -10,7 +10,7 @@ import UM.VersionUpgrade # of the file format. # # \param serialised The serialised form of a profile in version 1. -# \param filename The supposed filename of the profile. +# \param filename The supposed filename of the profile, without extension. # \return A profile instance, or None if the file format is incorrect. def importFrom(serialised, filename): try: @@ -24,7 +24,7 @@ class Profile: ## Reads version 1 of the file format, storing it in memory. # # \param serialised A string with the contents of a profile. - # \param filename The supposed filename of the profile. + # \param filename The supposed filename of the profile, without extension. def __init__(self, serialised, filename): self._filename = filename diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py index ae2356d720..a45a4a6e79 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/VersionUpgrade21to22.py @@ -66,7 +66,8 @@ class VersionUpgrade21to22(VersionUpgrade): ## Converts machine instances from format version 1 to version 2. # # \param serialised The serialised machine instance in version 1. - # \param filename The supposed file name of the machine instance. + # \param filename The supposed file name of the machine instance, without + # extension. # \return A tuple containing the new filename and the serialised machine # instance in version 2, or None if the input was not of the correct # format. @@ -79,7 +80,8 @@ class VersionUpgrade21to22(VersionUpgrade): ## Converts preferences from format version 2 to version 3. # # \param serialised The serialised preferences file in version 2. - # \param filename THe supposed file name of the preferences file. + # \param filename THe supposed file name of the preferences file, without + # extension. # \return A tuple containing the new filename and the serialised # preferences in version 3, or None if the input was not of the correct # format. @@ -92,7 +94,8 @@ class VersionUpgrade21to22(VersionUpgrade): ## Converts profiles from format version 1 to version 2. # # \param serialised The serialised profile in version 1. - # \param filename The supposed file name of the profile. + # \param filename The supposed file name of the profile, without + # extension. # \return A tuple containing the new filename and the serialised profile # in version 2, or None if the input was not of the correct format. def upgradeProfile(self, serialised, filename):