VersionUpgrade33to34.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser #To parse preference files.
  4. import io #To serialise the preference files afterwards.
  5. from typing import Dict, List, Tuple
  6. from UM.VersionUpgrade import VersionUpgrade #We're inheriting from this.
  7. _renamed_settings = {
  8. "infill_hollow": "infill_support_enabled"
  9. } # type: Dict[str, str]
  10. ## Upgrades configurations from the state they were in at version 3.3 to the
  11. # state they should be in at version 3.4.
  12. class VersionUpgrade33to34(VersionUpgrade):
  13. ## Upgrades instance containers to have the new version
  14. # number.
  15. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  16. parser = configparser.ConfigParser(interpolation = None)
  17. parser.read_string(serialized)
  18. # Update version number.
  19. parser["general"]["version"] = "4"
  20. if "values" in parser:
  21. #If infill_hollow was enabled and the overhang angle was adjusted, copy that overhang angle to the new infill support angle.
  22. if "infill_hollow" in parser["values"] and parser["values"]["infill_hollow"] and "support_angle" in parser["values"]:
  23. parser["values"]["infill_support_angle"] = parser["values"]["support_angle"]
  24. #Renamed settings.
  25. for original, replacement in _renamed_settings.items():
  26. if original in parser["values"]:
  27. parser["values"][replacement] = parser["values"][original]
  28. del parser["values"][original]
  29. result = io.StringIO()
  30. parser.write(result)
  31. return [filename], [result.getvalue()]