From 7b4cb1124082854a39d201050edb48ece00f1b9d Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Fri, 1 Dec 2017 11:05:15 +0100 Subject: [PATCH] Fix legacy profile upgrade CURA-4075 Only for single-extrusion machines just like before. --- .../LegacyProfileReader.py | 25 +++++++++++++++---- .../VersionUpgrade21to22/Profile.py | 2 +- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/plugins/LegacyProfileReader/LegacyProfileReader.py b/plugins/LegacyProfileReader/LegacyProfileReader.py index 3d680f2b97..ca04ec4b36 100644 --- a/plugins/LegacyProfileReader/LegacyProfileReader.py +++ b/plugins/LegacyProfileReader/LegacyProfileReader.py @@ -2,6 +2,7 @@ # Cura is released under the terms of the LGPLv3 or higher. import configparser # For reading the legacy profile INI files. +import io import json # For reading the Dictionary of Doom. import math # For mathematical operations included in the Dictionary of Doom. import os.path # For concatenating the path to the plugin and the relative path to the Dictionary of Doom. @@ -80,8 +81,7 @@ class LegacyProfileReader(ProfileReader): parser = configparser.ConfigParser(interpolation = None) try: - with open(file_name) as f: - parser.readfp(f) # Parse the INI file. + parser.read([file_name]) # Parse the INI file. except Exception as e: Logger.log("e", "Unable to open legacy profile %s: %s", file_name, str(e)) return None @@ -138,7 +138,22 @@ class LegacyProfileReader(ProfileReader): if len(profile.getAllKeys()) == 0: Logger.log("i", "A legacy profile was imported but everything evaluates to the defaults, creating an empty profile.") - profile.setDirty(True) - profile.addMetaDataEntry("type", "quality_changes") + + + # We need to downgrade the container to version 1 (in Cura 2.1) so the upgrade system can correctly upgrade + # it to the latest version. + profile.addMetaDataEntry("type", "profile") + # don't know what quality_type it is based on, so use "normal" by default profile.addMetaDataEntry("quality_type", "normal") - return profile \ No newline at end of file + profile.setDirty(True) + + parser = configparser.ConfigParser(interpolation=None) + data = profile.serialize() + parser.read_string(data) + parser["general"]["version"] = "1" + stream = io.StringIO() + parser.write(stream) + data = stream.getvalue() + profile.deserialize(data) + + return profile diff --git a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py index 4316d5cafb..becf29c242 100644 --- a/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py +++ b/plugins/VersionUpgrade/VersionUpgrade21to22/Profile.py @@ -98,7 +98,7 @@ class Profile: config.add_section("metadata") config.set("metadata", "quality_type", "normal") #This feature doesn't exist in 2.1 yet, so we don't know the actual quality type. For now, always base it on normal. - config.set("metadata", "type", "quality_changes") + config.set("metadata", "type", "quality") if self._weight: config.set("metadata", "weight", str(self._weight)) if self._machine_variant_name: