VersionUpgrade47to48.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 VersionUpgrade47to48(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"] = "16"
  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 this also changes the unit of the Scaling Factor Shrinkage
  27. Compensation setting.
  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"] = "16"
  37. if "values" in parser:
  38. # Shrinkage factor used to be a percentage based around 0% (where 0% meant that it doesn't shrink or expand).
  39. # Since 4.8, it is a percentage based around 100% (where 100% means that it doesn't shrink or expand).
  40. if "material_shrinkage_percentage" in parser["values"]:
  41. shrinkage_percentage = parser["values"]["meshfix_maximum_deviation"]
  42. if shrinkage_percentage.startswith("="):
  43. shrinkage_percentage = shrinkage_percentage[1:]
  44. shrinkage_percentage = "=(" + shrinkage_percentage + ") + 100"
  45. parser["values"]["material_shrinkage_percentage"] = shrinkage_percentage
  46. result = io.StringIO()
  47. parser.write(result)
  48. return [filename], [result.getvalue()]
  49. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  50. """
  51. Upgrades stacks to have the new version number.
  52. :param serialized: The original contents of the stack.
  53. :param filename: The original file name of the stack.
  54. :return: A list of new file names, and a list of the new contents for
  55. those files.
  56. """
  57. parser = configparser.ConfigParser(interpolation = None)
  58. parser.read_string(serialized)
  59. # Update version number.
  60. if "metadata" not in parser:
  61. parser["metadata"] = {}
  62. parser["metadata"]["setting_version"] = "16"
  63. result = io.StringIO()
  64. parser.write(result)
  65. return [filename], [result.getvalue()]