From 5143d0b9f15b5d61ad081d852d347a4da7c5b8a4 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Thu, 23 Jun 2016 12:03:44 +0200 Subject: [PATCH] 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.