VersionUpgrade53to54.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. # Copyright (c) 2023 UltiMaker
  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. _REMOVED_SETTINGS = {
  8. "wireframe_enabled",
  9. "wireframe_height",
  10. "wireframe_roof_inset",
  11. "wireframe_printspeed",
  12. "wireframe_printspeed_bottom",
  13. "wireframe_printspeed_up",
  14. "wireframe_printspeed_down",
  15. "wireframe_printspeed_flat",
  16. "wireframe_flow",
  17. "wireframe_flow_connection",
  18. "wireframe_flow_flat",
  19. "wireframe_top_delay",
  20. "wireframe_bottom_delay",
  21. "wireframe_flat_delay",
  22. "wireframe_up_half_speed",
  23. "wireframe_top_jump",
  24. "wireframe_fall_down",
  25. "wireframe_drag_along",
  26. "wireframe_strategy",
  27. "wireframe_straight_before_down",
  28. "wireframe_roof_fall_down",
  29. "wireframe_roof_drag_along",
  30. "wireframe_roof_outer_delay",
  31. "wireframe_nozzle_clearance",
  32. }
  33. class VersionUpgrade53to54(VersionUpgrade):
  34. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  35. """
  36. Upgrades preferences to remove from the visibility list the settings that were removed in this version.
  37. It also changes the preferences to have the new version number.
  38. This removes any settings that were removed in the new Cura version.
  39. :param serialized: The original contents of the preferences file.
  40. :param filename: The file name of the preferences file.
  41. :return: A list of new file names, and a list of the new contents for
  42. those files.
  43. """
  44. parser = configparser.ConfigParser(interpolation = None)
  45. parser.read_string(serialized)
  46. # Update version number.
  47. parser["metadata"]["setting_version"] = "22"
  48. # Remove deleted settings from the visible settings list.
  49. if "general" in parser and "visible_settings" in parser["general"]:
  50. visible_settings = set(parser["general"]["visible_settings"].split(";"))
  51. for removed in _REMOVED_SETTINGS:
  52. if removed in visible_settings:
  53. visible_settings.remove(removed)
  54. parser["general"]["visible_settings"] = ";".join(visible_settings)
  55. result = io.StringIO()
  56. parser.write(result)
  57. return [filename], [result.getvalue()]
  58. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  59. """
  60. Upgrades instance containers to remove the settings that were removed in this version.
  61. It also changes the instance containers to have the new version number.
  62. This removes any settings that were removed in the new Cura version and updates settings that need to be updated
  63. with a new value.
  64. :param serialized: The original contents of the instance container.
  65. :param filename: The original file name of the instance container.
  66. :return: A list of new file names, and a list of the new contents for
  67. those files.
  68. """
  69. parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ())
  70. parser.read_string(serialized)
  71. # Update version number.
  72. parser["metadata"]["setting_version"] = "22"
  73. if "values" in parser:
  74. # Remove deleted settings from the instance containers.
  75. for removed in _REMOVED_SETTINGS:
  76. if removed in parser["values"]:
  77. del parser["values"][removed]
  78. result = io.StringIO()
  79. parser.write(result)
  80. return [filename], [result.getvalue()]
  81. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  82. """
  83. Upgrades stacks to have the new version number.
  84. :param serialized: The original contents of the stack.
  85. :param filename: The original file name of the stack.
  86. :return: A list of new file names, and a list of the new contents for
  87. those files.
  88. """
  89. parser = configparser.ConfigParser(interpolation = None)
  90. parser.read_string(serialized)
  91. # Update version number.
  92. if "metadata" not in parser:
  93. parser["metadata"] = {}
  94. parser["metadata"]["setting_version"] = "22"
  95. result = io.StringIO()
  96. parser.write(result)
  97. return [filename], [result.getvalue()]