VersionUpgrade33to34.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. _renamed_settings = {
  7. "infill_hollow": "infill_support_enabled"
  8. }
  9. ## Upgrades configurations from the state they were in at version 3.3 to the
  10. # state they should be in at version 3.4.
  11. class VersionUpgrade33to34(VersionUpgrade):
  12. ## Gets the version number from a CFG file in Uranium's 3.3 format.
  13. #
  14. # Since the format may change, this is implemented for the 3.3 format only
  15. # and needs to be included in the version upgrade system rather than
  16. # globally in Uranium.
  17. #
  18. # \param serialised The serialised form of a CFG file.
  19. # \return The version number stored in the CFG file.
  20. # \raises ValueError The format of the version number in the file is
  21. # incorrect.
  22. # \raises KeyError The format of the file is incorrect.
  23. def getCfgVersion(self, serialised):
  24. parser = configparser.ConfigParser(interpolation = None)
  25. parser.read_string(serialised)
  26. format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  27. setting_version = int(parser.get("metadata", "setting_version", fallback = 0))
  28. return format_version * 1000000 + setting_version
  29. ## Upgrades instance containers to have the new version
  30. # number.
  31. def upgradeInstanceContainer(self, serialized, filename):
  32. parser = configparser.ConfigParser(interpolation = None)
  33. parser.read_string(serialized)
  34. # Update version number.
  35. parser["general"]["version"] = "4"
  36. if "values" in parser:
  37. #If infill_hollow was enabled and the overhang angle was adjusted, copy that overhang angle to the new infill support angle.
  38. if "infill_hollow" in parser["values"] and parser["values"]["infill_hollow"] and "support_angle" in parser["values"]:
  39. parser["values"]["infill_support_angle"] = parser["values"]["support_angle"]
  40. #Renamed settings.
  41. for original, replacement in _renamed_settings.items():
  42. if original in parser["values"]:
  43. parser["values"][replacement] = parser["values"][original]
  44. del parser["values"][original]
  45. result = io.StringIO()
  46. parser.write(result)
  47. return [filename], [result.getvalue()]