diff options
author | Ghostkeeper <rubend@tutanota.com> | 2021-05-18 18:19:06 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2021-05-18 18:37:08 +0300 |
commit | a00b21a802dacb46371b44d3c2a7de6bc5a708c9 (patch) | |
tree | aa554b040a92e464f1d97ec7fabc01f038dd2ec1 /plugins/VersionUpgrade/VersionUpgrade49to410 | |
parent | 6f5c3a0c4c392df3c8a0347fc86bea8cc0f044a1 (diff) |
Be more robust to broken input files
We've seen from experience that people do end up with broken files, due to user-modifications and whatnot. Corrupting it further won't make things better for the user.
Contributes to issue CURA-8212.
Diffstat (limited to 'plugins/VersionUpgrade/VersionUpgrade49to410')
-rw-r--r-- | plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py b/plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py index f7bbf8c0e6..8f38f6f851 100644 --- a/plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py +++ b/plugins/VersionUpgrade/VersionUpgrade49to410/VersionUpgrade49to410.py @@ -103,20 +103,24 @@ class VersionUpgrade49to410(VersionUpgrade): parser.read_string(serialized) # Update setting version number. + if "metadata" not in parser: + parser["metadata"] = {} parser["metadata"]["setting_version"] = "17" + if "general" not in parser: + parser["general"] = {} # Certain instance containers (such as definition changes) reference to a certain definition container # Since a number of those changed name, we also need to update those. - old_definition = parser["general"]["definition"] + old_definition = parser.get("general", "definition", fallback = "") if old_definition in self._renamed_profiles: parser["general"]["definition"] = self._renamed_profiles[old_definition] # For quality-changes profiles made for TwoTrees Bluer printers, change the definition to the two_trees_base and make sure that the quality is something we have a profile for. - if parser["metadata"].get("type", "") == "quality_changes": + if parser.get("metadata", "type", fallback = "") == "quality_changes": for possible_printer in self._quality_changes_to_two_trees_base: if os.path.basename(filename).startswith(possible_printer + "_"): parser["general"]["definition"] = "two_trees_base" - parser["metadata"]["quality_type"] = self._two_trees_bluer_quality_type_conversion.get(parser["metadata"]["quality_type"], "standard") + parser["metadata"]["quality_type"] = self._two_trees_bluer_quality_type_conversion.get(parser.get("metadata", "quality_type", fallback = "fast"), "standard") break result = io.StringIO() @@ -130,6 +134,8 @@ class VersionUpgrade49to410(VersionUpgrade): parser.read_string(serialized) # Update setting version number. + if "metadata" not in parser: + parser["metadata"] = {} parser["metadata"]["setting_version"] = "17" # Change renamed profiles. |