From e30d15ab666087f6f8411196060a056b592a24ec Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Fri, 9 Mar 2018 14:02:15 +0100 Subject: [PATCH] Implement getCfgVersion Mostly copied from the implementation in the 3.0 to 3.1 upgrade. Contributes to issue CURA-5054. --- .../VersionUpgrade32to33.py | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/plugins/VersionUpgrade/VersionUpgrade32to33/VersionUpgrade32to33.py b/plugins/VersionUpgrade/VersionUpgrade32to33/VersionUpgrade32to33.py index 64eded8b2e..6f7dbeccef 100644 --- a/plugins/VersionUpgrade/VersionUpgrade32to33/VersionUpgrade32to33.py +++ b/plugins/VersionUpgrade/VersionUpgrade32to33/VersionUpgrade32to33.py @@ -9,9 +9,23 @@ from UM.VersionUpgrade import VersionUpgrade #We're inheriting from this. ## Upgrades configurations from the state they were in at version 3.2 to the # state they should be in at version 3.3. class VersionUpgrade32to33(VersionUpgrade): - ## Gets the version number from a CFG file. - def getCfgVersion(self, serialized): - raise NotImplementedError("This has not yet been implemented.") + ## Gets the version number from a CFG file in Uranium's 3.2 format. + # + # Since the format may change, this is implemented for the 3.2 format only + # and needs to be included in the version upgrade system rather than + # globally in Uranium. + # + # \param serialised The serialised form of a CFG file. + # \return The version number stored in the CFG file. + # \raises ValueError The format of the version number in the file is + # incorrect. + # \raises KeyError The format of the file is incorrect. + def getCfgVersion(self, serialised): + parser = configparser.ConfigParser(interpolation = None) + parser.read_string(serialised) + format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised. + setting_version = int(parser.get("metadata", "setting_version", fallback = 0)) + return format_version * 1000000 + setting_version ## Upgrades a quality container to the new format. def upgradeQuality(self, serialized, filename):