VersionUpgrade35to40.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import configparser
  2. from typing import Tuple, List, Set, Dict
  3. import io
  4. from UM.VersionUpgrade import VersionUpgrade
  5. from cura.PrinterOutput.PrinterOutputDevice import ConnectionType
  6. deleted_settings = {"bridge_wall_max_overhang"} # type: Set[str]
  7. renamed_configurations = {"connect_group_name": "group_name"} # type: Dict[str, str]
  8. class VersionUpgrade35to40(VersionUpgrade):
  9. # Upgrades stacks to have the new version number.
  10. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  11. parser = configparser.ConfigParser(interpolation=None)
  12. parser.read_string(serialized)
  13. # Update version number.
  14. parser["general"]["version"] = "4"
  15. parser["metadata"]["setting_version"] = "6"
  16. if parser["metadata"].get("um_network_key") is not None or parser["metadata"].get("octoprint_api_key") is not None:
  17. # Set the connection type if um_network_key or the octoprint key is set.
  18. parser["metadata"]["connection_type"] = str(ConnectionType.NetworkConnection.value)
  19. if "metadata" in parser:
  20. for old_name, new_name in renamed_configurations.items():
  21. if old_name not in parser["metadata"]:
  22. continue
  23. parser["metadata"][new_name] = parser["metadata"][old_name]
  24. del parser["metadata"][old_name]
  25. result = io.StringIO()
  26. parser.write(result)
  27. return [filename], [result.getvalue()]
  28. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  29. """Upgrades Preferences to have the new version number."""
  30. parser = configparser.ConfigParser(interpolation=None)
  31. parser.read_string(serialized)
  32. if "metadata" not in parser:
  33. parser["metadata"] = {}
  34. parser["general"]["version"] = "6"
  35. parser["metadata"]["setting_version"] = "6"
  36. result = io.StringIO()
  37. parser.write(result)
  38. return [filename], [result.getvalue()]
  39. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  40. """Upgrades instance containers to have the new version number."""
  41. parser = configparser.ConfigParser(interpolation=None)
  42. parser.read_string(serialized)
  43. # Update version number.
  44. parser["general"]["version"] = "4"
  45. parser["metadata"]["setting_version"] = "6"
  46. #self._resetConcentric3DInfillPattern(parser)
  47. if "values" in parser:
  48. for deleted_setting in deleted_settings:
  49. if deleted_setting not in parser["values"]:
  50. continue
  51. del parser["values"][deleted_setting]
  52. result = io.StringIO()
  53. parser.write(result)
  54. return [filename], [result.getvalue()]