VersionUpgrade35to40.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import configparser
  2. from typing import Tuple, List, Set
  3. import io
  4. from UM.VersionUpgrade import VersionUpgrade
  5. from cura.PrinterOutputDevice import ConnectionType
  6. deleted_settings = {"bridge_wall_max_overhang"} # type: Set[str]
  7. class VersionUpgrade35to40(VersionUpgrade):
  8. # Upgrades stacks to have the new version number.
  9. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  10. parser = configparser.ConfigParser(interpolation=None)
  11. parser.read_string(serialized)
  12. # Update version number.
  13. parser["general"]["version"] = "4"
  14. parser["metadata"]["setting_version"] = "6"
  15. if parser["metadata"].get("um_network_key") is not None or parser["metadata"].get("octoprint_api_key") is not None:
  16. # Set the connection type if um_network_key or the octoprint key is set.
  17. parser["metadata"]["connection_type"] = str(ConnectionType.NetworkConnection.value)
  18. result = io.StringIO()
  19. parser.write(result)
  20. return [filename], [result.getvalue()]
  21. pass
  22. def getCfgVersion(self, serialised: str) -> int:
  23. parser = configparser.ConfigParser(interpolation = None)
  24. parser.read_string(serialised)
  25. format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  26. setting_version = int(parser.get("metadata", "setting_version", fallback = "0"))
  27. return format_version * 1000000 + setting_version
  28. ## Upgrades Preferences to have the new version number.
  29. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  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. ## Upgrades instance containers to have the new version
  40. # number.
  41. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  42. parser = configparser.ConfigParser(interpolation=None)
  43. parser.read_string(serialized)
  44. # Update version number.
  45. parser["general"]["version"] = "4"
  46. parser["metadata"]["setting_version"] = "6"
  47. #self._resetConcentric3DInfillPattern(parser)
  48. if "values" in parser:
  49. for deleted_setting in deleted_settings:
  50. if deleted_setting not in parser["values"]:
  51. continue
  52. del parser["values"][deleted_setting]
  53. result = io.StringIO()
  54. parser.write(result)
  55. return [filename], [result.getvalue()]