VersionUpgrade33to34.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser #To parse preference files.
  4. import io #To serialise the preference files afterwards.
  5. from UM.VersionUpgrade import VersionUpgrade #We're inheriting from this.
  6. ## Upgrades configurations from the state they were in at version 3.2 to the
  7. # state they should be in at version 3.3.
  8. class VersionUpgrade33to34(VersionUpgrade):
  9. ## Gets the version number from a CFG file in Uranium's 3.2 format.
  10. #
  11. # Since the format may change, this is implemented for the 3.2 format only
  12. # and needs to be included in the version upgrade system rather than
  13. # globally in Uranium.
  14. #
  15. # \param serialised The serialised form of a CFG file.
  16. # \return The version number stored in the CFG file.
  17. # \raises ValueError The format of the version number in the file is
  18. # incorrect.
  19. # \raises KeyError The format of the file is incorrect.
  20. def getCfgVersion(self, serialised):
  21. parser = configparser.ConfigParser(interpolation = None)
  22. parser.read_string(serialised)
  23. format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  24. setting_version = int(parser.get("metadata", "setting_version", fallback = 0))
  25. return format_version * 1000000 + setting_version
  26. ## Upgrades instance containers to have the new version
  27. # number.
  28. def upgradeInstanceContainer(self, serialized, filename):
  29. parser = configparser.ConfigParser(interpolation = None)
  30. parser.read_string(serialized)
  31. # Update version number.
  32. parser["general"]["version"] = "4"
  33. result = io.StringIO()
  34. parser.write(result)
  35. return [filename], [result.getvalue()]