VersionUpgrade34to40.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser
  4. import io
  5. from UM.VersionUpgrade import VersionUpgrade
  6. ## Upgrades configurations from the state they were in at version 3.4 to the
  7. # state they should be in at version 4.0.
  8. class VersionUpgrade34to40(VersionUpgrade):
  9. ## Gets the version number from a CFG file in Uranium's 3.3 format.
  10. #
  11. # Since the format may change, this is implemented for the 3.3 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 Preferences to have the new version number.
  27. def upgradePreferences(self, serialized, filename):
  28. parser = configparser.ConfigParser(interpolation = None)
  29. parser.read_string(serialized)
  30. # Update version number.
  31. parser["general"]["version"] = "4"
  32. if "metadata" not in parser:
  33. parser["metadata"] = {}
  34. parser["metadata"]["setting_version"] = "5"
  35. result = io.StringIO()
  36. parser.write(result)
  37. return [filename], [result.getvalue()]
  38. ## Upgrades stacks to have the new version number.
  39. def upgradeStack(self, serialized, filename):
  40. parser = configparser.ConfigParser(interpolation = None)
  41. parser.read_string(serialized)
  42. # Update version number.
  43. parser["general"]["version"] = "4"
  44. parser["metadata"]["setting_version"] = "5"
  45. result = io.StringIO()
  46. parser.write(result)
  47. return [filename], [result.getvalue()]
  48. ## Upgrades instance containers to have the new version
  49. # number.
  50. def upgradeInstanceContainer(self, serialized, filename):
  51. parser = configparser.ConfigParser(interpolation = None)
  52. parser.read_string(serialized)
  53. # Update version number.
  54. parser["general"]["version"] = "4"
  55. parser["metadata"]["setting_version"] = "5"
  56. self._resetConcentric3DInfillPattern(parser)
  57. result = io.StringIO()
  58. parser.write(result)
  59. return [filename], [result.getvalue()]
  60. def _resetConcentric3DInfillPattern(self, parser):
  61. if "values" not in parser:
  62. return
  63. # Reset the patterns which are concentric 3d
  64. for key in ("infill_pattern",
  65. "support_pattern",
  66. "support_interface_pattern",
  67. "support_roof_pattern",
  68. "support_bottom_pattern",
  69. ):
  70. if key not in parser["values"]:
  71. continue
  72. if parser["values"][key] == "concentric_3d":
  73. del parser["values"][key]