VersionUpgrade40to41.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. 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. # Limit Maximum Deviation instead of Maximum Resolution. This should have approximately the same effect as before the algorithm change, only more consistent.
  46. if "meshfix_maximum_resolution" in parser["values"]:
  47. resolution = parser["values"]["meshfix_maximum_resolution"]
  48. if resolution.startswith("="):
  49. resolution = resolution[1:]
  50. deviation = "=(" + resolution + ") / 2"
  51. parser["values"]["meshfix_maximum_deviation"] = deviation
  52. del parser["values"]["meshfix_maximum_resolution"]
  53. result = io.StringIO()
  54. parser.write(result)
  55. return [filename], [result.getvalue()]
  56. ## Upgrades Preferences to have the new version number.
  57. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  58. parser = configparser.ConfigParser(interpolation = None)
  59. parser.read_string(serialized)
  60. # Update version number.
  61. parser["general"]["version"] = "6"
  62. if "metadata" not in parser:
  63. parser["metadata"] = {}
  64. # Remove changelog plugin
  65. if "latest_version_changelog_shown" in parser["general"]:
  66. del parser["general"]["latest_version_changelog_shown"]
  67. parser["metadata"]["setting_version"] = "7"
  68. result = io.StringIO()
  69. parser.write(result)
  70. return [filename], [result.getvalue()]
  71. ## Upgrades stacks to have the new version number.
  72. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  73. parser = configparser.ConfigParser(interpolation = None)
  74. parser.read_string(serialized)
  75. # Update version number.
  76. parser["general"]["version"] = "4"
  77. parser["metadata"]["setting_version"] = "7"
  78. #Update the name of the quality profile.
  79. if parser["containers"]["4"] in _renamed_quality_profiles:
  80. parser["containers"]["4"] = _renamed_quality_profiles[parser["containers"]["4"]]
  81. result = io.StringIO()
  82. parser.write(result)
  83. return [filename], [result.getvalue()]