VersionUpgrade40to41.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. import uuid
  6. from typing import Dict, List, Tuple
  7. from UM.VersionUpgrade import VersionUpgrade
  8. _renamed_quality_profiles = {
  9. "gmax15plus_pla_dual_normal": "gmax15plus_global_dual_normal",
  10. "gmax15plus_pla_dual_thick": "gmax15plus_global_dual_thick",
  11. "gmax15plus_pla_dual_thin": "gmax15plus_global_dual_thin",
  12. "gmax15plus_pla_dual_very_thick": "gmax15plus_global_dual_very_thick",
  13. "gmax15plus_pla_normal": "gmax15plus_global_normal",
  14. "gmax15plus_pla_thick": "gmax15plus_global_thick",
  15. "gmax15plus_pla_thin": "gmax15plus_global_thin",
  16. "gmax15plus_pla_very_thick": "gmax15plus_global_very_thick"
  17. } # type: Dict[str, str]
  18. ## Upgrades configurations from the state they were in at version 4.0 to the
  19. # state they should be in at version 4.1.
  20. class VersionUpgrade40to41(VersionUpgrade):
  21. ## Gets the version number from a CFG file in Uranium's 4.0 format.
  22. #
  23. # Since the format may change, this is implemented for the 4.0 format only
  24. # and needs to be included in the version upgrade system rather than
  25. # globally in Uranium.
  26. #
  27. # \param serialised The serialised form of a CFG file.
  28. # \return The version number stored in the CFG file.
  29. # \raises ValueError The format of the version number in the file is
  30. # incorrect.
  31. # \raises KeyError The format of the file is incorrect.
  32. def getCfgVersion(self, serialised: str) -> int:
  33. parser = configparser.ConfigParser(interpolation = None)
  34. parser.read_string(serialised)
  35. format_version = int(parser.get("general", "version")) #Explicitly give an exception when this fails. That means that the file format is not recognised.
  36. setting_version = int(parser.get("metadata", "setting_version", fallback = "0"))
  37. return format_version * 1000000 + setting_version
  38. ## Upgrades instance containers to have the new version
  39. # number.
  40. def upgradeInstanceContainer(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  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"] = "7"
  46. # Limit Maximum Deviation instead of Maximum Resolution. This should have approximately the same effect as before the algorithm change, only more consistent.
  47. if "values" in parser and "meshfix_maximum_resolution" in parser["values"]:
  48. resolution = parser["values"]["meshfix_maximum_resolution"]
  49. if resolution.startswith("="):
  50. resolution = resolution[1:]
  51. deviation = "=(" + resolution + ") / 2"
  52. parser["values"]["meshfix_maximum_deviation"] = deviation
  53. del parser["values"]["meshfix_maximum_resolution"]
  54. result = io.StringIO()
  55. parser.write(result)
  56. return [filename], [result.getvalue()]
  57. ## Upgrades Preferences to have the new version number.
  58. def upgradePreferences(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  59. parser = configparser.ConfigParser(interpolation = None)
  60. parser.read_string(serialized)
  61. # Update version number.
  62. parser["general"]["version"] = "6"
  63. if "metadata" not in parser:
  64. parser["metadata"] = {}
  65. # Remove changelog plugin
  66. if "latest_version_changelog_shown" in parser["general"]:
  67. del parser["general"]["latest_version_changelog_shown"]
  68. parser["metadata"]["setting_version"] = "7"
  69. result = io.StringIO()
  70. parser.write(result)
  71. return [filename], [result.getvalue()]
  72. ## Upgrades stacks to have the new version number.
  73. def upgradeStack(self, serialized: str, filename: str) -> Tuple[List[str], List[str]]:
  74. parser = configparser.ConfigParser(interpolation = None)
  75. parser.read_string(serialized)
  76. # Update version number.
  77. parser["general"]["version"] = "4"
  78. parser["metadata"]["setting_version"] = "7"
  79. #Update the name of the quality profile.
  80. if parser["containers"]["4"] in _renamed_quality_profiles:
  81. parser["containers"]["4"] = _renamed_quality_profiles[parser["containers"]["4"]]
  82. # Assign a GlobalStack to a unique group_id. If the GlobalStack has a UM network connection, use the UM network
  83. # key as the group_id.
  84. if "um_network_key" in parser["metadata"]:
  85. parser["metadata"]["group_id"] = parser["metadata"]["um_network_key"]
  86. elif "group_id" not in parser["metadata"]:
  87. parser["metadata"]["group_id"] = str(uuid.uuid4())
  88. result = io.StringIO()
  89. parser.write(result)
  90. return [filename], [result.getvalue()]