VersionUpgrade460to462.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # Copyright (c) 2020 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser
  4. from typing import Tuple, List
  5. import io
  6. from UM.VersionUpgrade import VersionUpgrade
  7. class VersionUpgrade460to462(VersionUpgrade):
  8. def getCfgVersion(self, serialised: str) -> int:
  9. parser = configparser.ConfigParser(interpolation = None)
  10. parser.read_string(serialised)
  11. format_version = int(parser.get("general", "version")) # Explicitly give an exception when this fails. That means that the file format is not recognised.
  12. setting_version = int(parser.get("metadata", "setting_version", fallback = "0"))
  13. return format_version * 1000000 + setting_version
  14. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  15. """
  16. Upgrades preferences to have the new version number.
  17. :param serialized: The original contents of the preferences file.
  18. :param filename: The file name of the preferences file.
  19. :return: A list of new file names, and a list of the new contents for
  20. those files.
  21. """
  22. parser = configparser.ConfigParser(interpolation = None)
  23. parser.read_string(serialized)
  24. # Update version number.
  25. parser["metadata"]["setting_version"] = "14"
  26. result = io.StringIO()
  27. parser.write(result)
  28. return [filename], [result.getvalue()]
  29. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  30. """
  31. Upgrades instance containers to have the new version number.
  32. This changes the maximum deviation setting if that setting was present
  33. in the profile.
  34. :param serialized: The original contents of the instance container.
  35. :param filename: The original file name of the instance container.
  36. :return: A list of new file names, and a list of the new contents for
  37. those files.
  38. """
  39. parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ())
  40. parser.read_string(serialized)
  41. # Update version number.
  42. parser["metadata"]["setting_version"] = "14"
  43. if "values" in parser:
  44. # Maximum Deviation's effect was corrected. Previously the deviation
  45. # ended up being only half of what the user had entered. This was
  46. # fixed in Cura 4.7 so there we need to halve the deviation that the
  47. # user had entered. This halving was accidentally merged into 4.6 and had to be reverted
  48. # back in 4.6.2.
  49. if "meshfix_maximum_deviation" in parser["values"]:
  50. maximum_deviation = parser["values"]["meshfix_maximum_deviation"]
  51. if maximum_deviation.startswith("="):
  52. maximum_deviation = maximum_deviation[1:]
  53. maximum_deviation = "=(" + maximum_deviation + ") * 2"
  54. parser["values"]["meshfix_maximum_deviation"] = maximum_deviation
  55. result = io.StringIO()
  56. parser.write(result)
  57. return [filename], [result.getvalue()]
  58. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  59. """
  60. Upgrades stacks to have the new version number.
  61. :param serialized: The original contents of the stack.
  62. :param filename: The original file name of the stack.
  63. :return: A list of new file names, and a list of the new contents for
  64. those files.
  65. """
  66. parser = configparser.ConfigParser(interpolation = None)
  67. parser.read_string(serialized)
  68. # Update version number.
  69. if "metadata" not in parser:
  70. parser["metadata"] = {}
  71. parser["metadata"]["setting_version"] = "14"
  72. result = io.StringIO()
  73. parser.write(result)
  74. return [filename], [result.getvalue()]