VersionUpgrade40to41.py 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser
  4. import io
  5. from typing import Dict, List, Tuple
  6. from UM.VersionUpgrade import VersionUpgrade
  7. _renamed_quality_profiles = {
  8. "gmax15plus_pla_dual_normal": "gmax15plus_global_dual_normal",
  9. "gmax15plus_pla_dual_thick": "gmax15plus_global_dual_thick",
  10. "gmax15plus_pla_dual_thin": "gmax15plus_global_dual_thin",
  11. "gmax15plus_pla_dual_very_thick": "gmax15plus_global_dual_very_thick",
  12. "gmax15plus_pla_normal": "gmax15plus_global_normal",
  13. "gmax15plus_pla_thick": "gmax15plus_global_thick",
  14. "gmax15plus_pla_thin": "gmax15plus_global_thin",
  15. "gmax15plus_pla_very_thick": "gmax15plus_global_very_thick"
  16. } # type: Dict[str, str]
  17. ## Upgrades configurations from the state they were in at version 4.0 to the
  18. # state they should be in at version 4.1.
  19. class VersionUpgrade40to41(VersionUpgrade):
  20. ## Gets the version number from a CFG file in Uranium's 4.0 format.
  21. #
  22. # Since the format may change, this is implemented for the 4.0 format only
  23. # and needs to be included in the version upgrade system rather than
  24. # globally in Uranium.
  25. #
  26. # \param serialised The serialised form of a CFG file.
  27. # \return The version number stored in the CFG file.
  28. # \raises ValueError The format of the version number in the file is
  29. # incorrect.
  30. # \raises KeyError The format of the file is incorrect.
  31. def getCfgVersion(self, serialised: str) -> int:
  32. parser = configparser.ConfigParser(interpolation = None)
  33. parser.read_string(serialised)
  34. format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  35. setting_version = int(parser.get("metadata", "setting_version", fallback = "0"))
  36. return format_version * 1000000 + setting_version
  37. ## Upgrades instance containers to have the new version
  38. # number.
  39. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  40. parser = configparser.ConfigParser(interpolation = None)
  41. parser.read_string(serialized)
  42. # Update version number.
  43. parser["general"]["version"] = "4"
  44. parser["metadata"]["setting_version"] = "7"
  45. result = io.StringIO()
  46. parser.write(result)
  47. return [filename], [result.getvalue()]
  48. ## Upgrades Preferences to have the new version number.
  49. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  50. parser = configparser.ConfigParser(interpolation = None)
  51. parser.read_string(serialized)
  52. # Update version number.
  53. parser["general"]["version"] = "6"
  54. if "metadata" not in parser:
  55. parser["metadata"] = {}
  56. parser["metadata"]["setting_version"] = "7"
  57. result = io.StringIO()
  58. parser.write(result)
  59. return [filename], [result.getvalue()]
  60. ## Upgrades stacks to have the new version number.
  61. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  62. parser = configparser.ConfigParser(interpolation = None)
  63. parser.read_string(serialized)
  64. # Update version number.
  65. parser["general"]["version"] = "4"
  66. parser["metadata"]["setting_version"] = "7"
  67. #Update the name of the quality profile.
  68. if parser["containers"]["4"] in _renamed_quality_profiles:
  69. parser["containers"]["4"] = _renamed_quality_profiles[parser["containers"]["4"]]
  70. result = io.StringIO()
  71. parser.write(result)
  72. return [filename], [result.getvalue()]