VersionUpgrade26to27.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. import configparser #To parse the files we need to upgrade and write the new files.
  4. import io #To serialise configparser output to a string.
  5. from typing import Dict, List, Tuple
  6. from UM.VersionUpgrade import VersionUpgrade
  7. # a dict of renamed quality profiles: <old_id> : <new_id>
  8. _renamed_quality_profiles = {
  9. "um3_aa0.4_PVA_Not_Supported_Quality": "um3_aa0.4_PVA_Fast_Print",
  10. "um3_aa0.8_CPEP_Not_Supported_Quality": "um3_aa0.8_CPEP_Fast_Print",
  11. "um3_aa0.8_CPEP_Not_Supported_Superdraft_Quality": "um3_aa0.8_CPEP_Superdraft_Print",
  12. "um3_aa0.8_CPEP_Not_Supported_Verydraft_Quality": "um3_aa0.8_CPEP_Verydraft_Print",
  13. "um3_aa0.8_PC_Not_Supported_Quality": "um3_aa0.8_PC_Fast_Print",
  14. "um3_aa0.8_PC_Not_Supported_Superdraft_Quality": "um3_aa0.8_PC_Superdraft_Print",
  15. "um3_aa0.8_PC_Not_Supported_Verydraft_Quality": "um3_aa0.8_PC_Verydraft_Print",
  16. "um3_aa0.8_PVA_Not_Supported_Quality": "um3_aa0.8_PVA_Fast_Print",
  17. "um3_aa0.8_PVA_Not_Supported_Superdraft_Quality": "um3_aa0.8_PVA_Superdraft_Print",
  18. "um3_bb0.4_ABS_Not_Supported_Quality": "um3_bb0.4_ABS_Fast_print",
  19. "um3_bb0.4_ABS_Not_Supported_Superdraft_Quality": "um3_bb0.4_ABS_Superdraft_Print",
  20. "um3_bb0.4_CPE_Not_Supported_Quality": "um3_bb0.4_CPE_Fast_Print",
  21. "um3_bb0.4_CPE_Not_Supported_Superdraft_Quality": "um3_bb0.4_CPE_Superdraft_Print",
  22. "um3_bb0.4_CPEP_Not_Supported_Quality": "um3_bb0.4_CPEP_Fast_Print",
  23. "um3_bb0.4_CPEP_Not_Supported_Superdraft_Quality": "um3_bb0.4_CPEP_Superdraft_Print",
  24. "um3_bb0.4_Nylon_Not_Supported_Quality": "um3_bb0.4_Nylon_Fast_Print",
  25. "um3_bb0.4_Nylon_Not_Supported_Superdraft_Quality": "um3_bb0.4_Nylon_Superdraft_Print",
  26. "um3_bb0.4_PC_Not_Supported_Quality": "um3_bb0.4_PC_Fast_Print",
  27. "um3_bb0.4_PLA_Not_Supported_Quality": "um3_bb0.4_PLA_Fast_Print",
  28. "um3_bb0.4_PLA_Not_Supported_Superdraft_Quality": "um3_bb0.4_PLA_Superdraft_Print",
  29. "um3_bb0.4_TPU_Not_Supported_Quality": "um3_bb0.4_TPU_Fast_Print",
  30. "um3_bb0.4_TPU_Not_Supported_Superdraft_Quality": "um3_bb0.4_TPU_Superdraft_Print",
  31. "um3_bb0.8_ABS_Not_Supported_Quality": "um3_bb0.8_ABS_Fast_Print",
  32. "um3_bb0.8_ABS_Not_Supported_Superdraft_Quality": "um3_bb0.8_ABS_Superdraft_Print",
  33. "um3_bb0.8_CPE_Not_Supported_Quality": "um3_bb0.8_CPE_Fast_Print",
  34. "um3_bb0.8_CPE_Not_Supported_Superdraft_Quality": "um3_bb0.8_CPE_Superdraft_Print",
  35. "um3_bb0.8_CPEP_Not_Supported_Quality": "um3_bb0.um3_bb0.8_CPEP_Fast_Print",
  36. "um3_bb0.8_CPEP_Not_Supported_Superdraft_Quality": "um3_bb0.8_CPEP_Superdraft_Print",
  37. "um3_bb0.8_Nylon_Not_Supported_Quality": "um3_bb0.8_Nylon_Fast_Print",
  38. "um3_bb0.8_Nylon_Not_Supported_Superdraft_Quality": "um3_bb0.8_Nylon_Superdraft_Print",
  39. "um3_bb0.8_PC_Not_Supported_Quality": "um3_bb0.8_PC_Fast_Print",
  40. "um3_bb0.8_PC_Not_Supported_Superdraft_Quality": "um3_bb0.8_PC_Superdraft_Print",
  41. "um3_bb0.8_PLA_Not_Supported_Quality": "um3_bb0.8_PLA_Fast_Print",
  42. "um3_bb0.8_PLA_Not_Supported_Superdraft_Quality": "um3_bb0.8_PLA_Superdraft_Print",
  43. "um3_bb0.8_TPU_Not_Supported_Quality": "um3_bb0.8_TPU_Fast_print",
  44. "um3_bb0.8_TPU_Not_Supported_Superdraft_Quality": "um3_bb0.8_TPU_Superdraft_Print",
  45. } # type: Dict[str, str]
  46. ## A collection of functions that convert the configuration of the user in Cura
  47. # 2.6 to a configuration for Cura 2.7.
  48. #
  49. # All of these methods are essentially stateless.
  50. class VersionUpgrade26to27(VersionUpgrade):
  51. ## Upgrades a preferences file from version 2.6 to 2.7.
  52. #
  53. # \param serialised The serialised form of a preferences file.
  54. # \param filename The name of the file to upgrade.
  55. def upgradePreferences(self, serialised: str, filename: str) -> Tuple[List[str], List[str]]:
  56. parser = configparser.ConfigParser(interpolation = None)
  57. parser.read_string(serialised)
  58. # Update version numbers
  59. if "general" not in parser:
  60. parser["general"] = {}
  61. parser["general"]["version"] = "4"
  62. if "metadata" not in parser:
  63. parser["metadata"] = {}
  64. parser["metadata"]["setting_version"] = "2"
  65. #Renamed setting value for g-code flavour.
  66. if "values" in parser and "machine_gcode_flavor" in parser["values"]:
  67. if parser["values"]["machine_gcode_flavor"] == "RepRap (Volumatric)":
  68. parser["values"]["machine_gcode_flavor"] = "RepRap (Volumetric)"
  69. # Re-serialise the file.
  70. output = io.StringIO()
  71. parser.write(output)
  72. return [filename], [output.getvalue()]
  73. ## Upgrades a container file other than a container stack file from version 2.6 to 2.7.
  74. #
  75. # \param serialised The serialised form of a container file.
  76. # \param filename The name of the file to upgrade.
  77. def upgradeOtherContainer(self, serialised: str, filename: str) -> Tuple[List[str], List[str]]:
  78. parser = configparser.ConfigParser(interpolation = None)
  79. parser.read_string(serialised)
  80. # Update version numbers
  81. if "general" not in parser:
  82. parser["general"] = {}
  83. parser["general"]["version"] = "2"
  84. if "metadata" not in parser:
  85. parser["metadata"] = {}
  86. parser["metadata"]["setting_version"] = "2"
  87. # Re-serialise the file.
  88. output = io.StringIO()
  89. parser.write(output)
  90. return [filename], [output.getvalue()]
  91. ## Upgrades a container stack from version 2.6 to 2.7.
  92. #
  93. # \param serialised The serialised form of a container stack.
  94. # \param filename The name of the file to upgrade.
  95. def upgradeStack(self, serialised: str, filename: str) -> Tuple[List[str], List[str]]:
  96. parser = configparser.ConfigParser(interpolation = None)
  97. parser.read_string(serialised)
  98. # Update IDs of the renamed quality profiles
  99. if parser.has_section("containers"):
  100. key_list = [key for key in parser["containers"].keys()]
  101. for key in key_list:
  102. container_id = parser.get("containers", key)
  103. new_id = _renamed_quality_profiles.get(container_id)
  104. if new_id is not None:
  105. parser.set("containers", key, new_id)
  106. if "6" not in parser["containers"]:
  107. parser["containers"]["6"] = parser["containers"]["5"]
  108. parser["containers"]["5"] = "empty"
  109. for each_section in ("general", "metadata"):
  110. if not parser.has_section(each_section):
  111. parser.add_section(each_section)
  112. # Update version numbers
  113. if "general" not in parser:
  114. parser["general"] = {}
  115. parser["general"]["version"] = "3"
  116. if "metadata" not in parser:
  117. parser["metadata"] = {}
  118. parser["metadata"]["setting_version"] = "2"
  119. # Re-serialise the file.
  120. output = io.StringIO()
  121. parser.write(output)
  122. return [filename], [output.getvalue()]