VersionUpgrade462to47.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 VersionUpgrade462to47(VersionUpgrade):
  8. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  9. """
  10. Upgrades preferences to have the new version number.
  11. :param serialized: The original contents of the preferences file.
  12. :param filename: The file name of the preferences file.
  13. :return: A list of new file names, and a list of the new contents for
  14. those files.
  15. """
  16. parser = configparser.ConfigParser(interpolation = None)
  17. parser.read_string(serialized)
  18. # Update version number.
  19. parser["metadata"]["setting_version"] = "15"
  20. result = io.StringIO()
  21. parser.write(result)
  22. return [filename], [result.getvalue()]
  23. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  24. """
  25. Upgrades instance containers to have the new version number.
  26. This changes the maximum deviation setting if that setting was present
  27. in the profile.
  28. :param serialized: The original contents of the instance container.
  29. :param filename: The original file name of the instance container.
  30. :return: A list of new file names, and a list of the new contents for
  31. those files.
  32. """
  33. parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ())
  34. parser.read_string(serialized)
  35. # Update version number.
  36. parser["metadata"]["setting_version"] = "15"
  37. if "values" in parser:
  38. # Maximum Deviation's effect was corrected. Previously the deviation
  39. # ended up being only half of what the user had entered. This was
  40. # fixed in Cura 4.7 so there we need to halve the deviation that the
  41. # user had entered.
  42. #
  43. # This got accidentally merged in Cura 4.6.0. In 4.6.2 we removed
  44. # that. In 4.7 it's not unmerged, so there we need to revert all
  45. # that again.
  46. if "meshfix_maximum_deviation" in parser["values"]:
  47. maximum_deviation = parser["values"]["meshfix_maximum_deviation"]
  48. if maximum_deviation.startswith("="):
  49. maximum_deviation = maximum_deviation[1:]
  50. maximum_deviation = "=(" + maximum_deviation + ") / 2"
  51. parser["values"]["meshfix_maximum_deviation"] = maximum_deviation
  52. result = io.StringIO()
  53. parser.write(result)
  54. return [filename], [result.getvalue()]
  55. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  56. """
  57. Upgrades stacks to have the new version number.
  58. :param serialized: The original contents of the stack.
  59. :param filename: The original file name of the stack.
  60. :return: A list of new file names, and a list of the new contents for
  61. those files.
  62. """
  63. parser = configparser.ConfigParser(interpolation = None)
  64. parser.read_string(serialized)
  65. # Update version number.
  66. if "metadata" not in parser:
  67. parser["metadata"] = {}
  68. parser["metadata"]["setting_version"] = "15"
  69. result = io.StringIO()
  70. parser.write(result)
  71. return [filename], [result.getvalue()]