VersionUpgrade56to57.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright (c) 2024 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. "support_interface_skip_height",
  9. }
  10. _NEW_SETTING_VERSION = "23"
  11. class VersionUpgrade56to57(VersionUpgrade):
  12. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  13. """
  14. Upgrades preferences to remove from the visibility list the settings that were removed in this version.
  15. It also changes the preferences to have the new version number.
  16. This removes any settings that were removed in the new Cura version.
  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"] = _NEW_SETTING_VERSION
  26. # Remove deleted settings from the visible settings list.
  27. if "general" in parser and "visible_settings" in parser["general"]:
  28. visible_settings = set(parser["general"]["visible_settings"].split(";"))
  29. for removed in _REMOVED_SETTINGS:
  30. if removed in visible_settings:
  31. visible_settings.remove(removed)
  32. parser["general"]["visible_settings"] = ";".join(visible_settings)
  33. result = io.StringIO()
  34. parser.write(result)
  35. return [filename], [result.getvalue()]
  36. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  37. """
  38. Upgrades instance containers to remove the settings that were removed in this version.
  39. It also changes the instance containers to have the new version number.
  40. This removes any settings that were removed in the new Cura version and updates settings that need to be updated
  41. with a new value.
  42. :param serialized: The original contents of the instance container.
  43. :param filename: The original file name of the instance container.
  44. :return: A list of new file names, and a list of the new contents for
  45. those files.
  46. """
  47. parser = configparser.ConfigParser(interpolation = None, comment_prefixes = ())
  48. parser.read_string(serialized)
  49. # Update version number.
  50. parser["metadata"]["setting_version"] = _NEW_SETTING_VERSION
  51. if "values" in parser:
  52. # Remove deleted settings from the instance containers.
  53. for removed in _REMOVED_SETTINGS:
  54. if removed in parser["values"]:
  55. del parser["values"][removed]
  56. result = io.StringIO()
  57. parser.write(result)
  58. return [filename], [result.getvalue()]
  59. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  60. """
  61. Upgrades stacks to have the new version number.
  62. :param serialized: The original contents of the stack.
  63. :param filename: The original file name of the stack.
  64. :return: A list of new file names, and a list of the new contents for
  65. those files.
  66. """
  67. parser = configparser.ConfigParser(interpolation = None)
  68. parser.read_string(serialized)
  69. # Update version number.
  70. if "metadata" not in parser:
  71. parser["metadata"] = {}
  72. parser["metadata"]["setting_version"] = _NEW_SETTING_VERSION
  73. result = io.StringIO()
  74. parser.write(result)
  75. return [filename], [result.getvalue()]