VersionUpgrade40to41.py 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # Copyright (c) 2019 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser
  4. import io
  5. import uuid
  6. from typing import Dict, List, Tuple
  7. from UM.VersionUpgrade import VersionUpgrade
  8. _renamed_quality_profiles = {
  9. "gmax15plus_pla_dual_normal": "gmax15plus_global_dual_normal",
  10. "gmax15plus_pla_dual_thick": "gmax15plus_global_dual_thick",
  11. "gmax15plus_pla_dual_thin": "gmax15plus_global_dual_thin",
  12. "gmax15plus_pla_dual_very_thick": "gmax15plus_global_dual_very_thick",
  13. "gmax15plus_pla_normal": "gmax15plus_global_normal",
  14. "gmax15plus_pla_thick": "gmax15plus_global_thick",
  15. "gmax15plus_pla_thin": "gmax15plus_global_thin",
  16. "gmax15plus_pla_very_thick": "gmax15plus_global_very_thick"
  17. } # type: Dict[str, str]
  18. class VersionUpgrade40to41(VersionUpgrade):
  19. """Upgrades configurations from the state they were in at version 4.0 to the
  20. state they should be in at version 4.1.
  21. """
  22. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  23. """Upgrades instance containers to have the new version number."""
  24. parser = configparser.ConfigParser(interpolation = None)
  25. parser.read_string(serialized)
  26. # Update version number.
  27. parser["general"]["version"] = "4"
  28. parser["metadata"]["setting_version"] = "7"
  29. # Limit Maximum Deviation instead of Maximum Resolution. This should have approximately the same effect as before the algorithm change, only more consistent.
  30. if "values" in parser and "meshfix_maximum_resolution" in parser["values"]:
  31. resolution = parser["values"]["meshfix_maximum_resolution"]
  32. if resolution.startswith("="):
  33. resolution = resolution[1:]
  34. deviation = "=(" + resolution + ") / 2"
  35. parser["values"]["meshfix_maximum_deviation"] = deviation
  36. del parser["values"]["meshfix_maximum_resolution"]
  37. result = io.StringIO()
  38. parser.write(result)
  39. return [filename], [result.getvalue()]
  40. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  41. """Upgrades Preferences to have the new version number."""
  42. parser = configparser.ConfigParser(interpolation = None)
  43. parser.read_string(serialized)
  44. # Update version number.
  45. parser["general"]["version"] = "6"
  46. if "metadata" not in parser:
  47. parser["metadata"] = {}
  48. # Remove changelog plugin
  49. if "latest_version_changelog_shown" in parser["general"]:
  50. del parser["general"]["latest_version_changelog_shown"]
  51. parser["metadata"]["setting_version"] = "7"
  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. """Upgrades stacks to have the new version number."""
  57. parser = configparser.ConfigParser(interpolation = None)
  58. parser.read_string(serialized)
  59. # Update version number.
  60. parser["general"]["version"] = "4"
  61. parser["metadata"]["setting_version"] = "7"
  62. #Update the name of the quality profile.
  63. if parser["containers"]["4"] in _renamed_quality_profiles:
  64. parser["containers"]["4"] = _renamed_quality_profiles[parser["containers"]["4"]]
  65. # Assign a GlobalStack to a unique group_id. If the GlobalStack has a UM network connection, use the UM network
  66. # key as the group_id.
  67. if "um_network_key" in parser["metadata"]:
  68. parser["metadata"]["group_id"] = parser["metadata"]["um_network_key"]
  69. elif "group_id" not in parser["metadata"]:
  70. parser["metadata"]["group_id"] = str(uuid.uuid4())
  71. result = io.StringIO()
  72. parser.write(result)
  73. return [filename], [result.getvalue()]