VersionUpgrade56to57.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. if "brim_outside_only" in parser["values"]:
  57. parser["values"]["brim_location"] = "outside" if parser["values"][
  58. "brim_outside_only"] == "True" else "everywhere"
  59. del parser["values"]["brim_outside_only"]
  60. result = io.StringIO()
  61. parser.write(result)
  62. return [filename], [result.getvalue()]
  63. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  64. """
  65. Upgrades stacks to have the new version number.
  66. :param serialized: The original contents of the stack.
  67. :param filename: The original file name of the stack.
  68. :return: A list of new file names, and a list of the new contents for
  69. those files.
  70. """
  71. parser = configparser.ConfigParser(interpolation = None)
  72. parser.read_string(serialized)
  73. # Update version number.
  74. if "metadata" not in parser:
  75. parser["metadata"] = {}
  76. parser["metadata"]["setting_version"] = _NEW_SETTING_VERSION
  77. result = io.StringIO()
  78. parser.write(result)
  79. return [filename], [result.getvalue()]