diff options
author | Lipu Fei <lipu.fei815@gmail.com> | 2017-05-19 12:05:59 +0300 |
---|---|---|
committer | Lipu Fei <lipu.fei815@gmail.com> | 2017-05-19 12:06:01 +0300 |
commit | 5a6049ddeab07f5433ebae39cbef6b1ce4d39710 (patch) | |
tree | c1ae9de8ab19bfb4b35e3a04d23636e7b1c43ce4 /plugins/XmlMaterialProfile/XmlMaterialUpgrader.py | |
parent | 70894608613d736555b131da37a2a61dba905e77 (diff) |
Change XmlMaterialUpgrader to use UNIX EOLs
CURA-3756
Diffstat (limited to 'plugins/XmlMaterialProfile/XmlMaterialUpgrader.py')
-rw-r--r-- | plugins/XmlMaterialProfile/XmlMaterialUpgrader.py | 124 |
1 files changed, 62 insertions, 62 deletions
diff --git a/plugins/XmlMaterialProfile/XmlMaterialUpgrader.py b/plugins/XmlMaterialProfile/XmlMaterialUpgrader.py index 9f5b3cef9d..8f1d1e9ec6 100644 --- a/plugins/XmlMaterialProfile/XmlMaterialUpgrader.py +++ b/plugins/XmlMaterialProfile/XmlMaterialUpgrader.py @@ -1,62 +1,62 @@ -# Copyright (c) 2017 Ultimaker B.V.
-# Cura is released under the terms of the AGPLv3 or higher.
-
-import xml.etree.ElementTree as ET
-
-from UM.VersionUpgrade import VersionUpgrade
-
-
-class XmlMaterialUpgrader(VersionUpgrade):
- def getXmlVersion(self, serialized):
- data = ET.fromstring(serialized)
-
- # get format version
- version = None
- metadata = data.iterfind("./um:metadata/*")
- for entry in metadata:
- tag_name = entry.tag
- if tag_name == "version":
- try:
- version = int(entry.text)
- except Exception as e:
- raise ValueError("Invalid version string '%s': %s" % (entry.text, e))
- break
- if version is None:
- raise RuntimeError("Missing version in metadata")
-
- # get setting version
- if "version" in data.attrib:
- setting_version = self._xmlVersionToSettingVersion(data.attrib["version"])
- else:
- setting_version = self._xmlVersionToSettingVersion("1.2")
-
- if version is None:
- raise RuntimeError("Missing version in metadata")
-
- return version * 1000000 + setting_version
-
- def _xmlVersionToSettingVersion(self, xml_version: str) -> int:
- if xml_version == "1.3":
- return 1
- return 0 #Older than 1.3.
-
- def upgradeMaterial(self, serialised, filename):
- data = ET.fromstring(serialised)
-
- # update version
- metadata = data.iterfind("./um:metadata/*", {"um": "http://www.ultimaker.com/material"})
- for entry in metadata:
- if _tag_without_namespace(entry) == "version":
- entry.text = "2"
- break
-
- data.attrib["version"] = "1.3"
-
- # this makes sure that the XML header states encoding="utf-8"
- new_serialised = ET.tostring(data, encoding="utf-8").decode("utf-8")
-
- return [filename], [new_serialised]
-
-
-def _tag_without_namespace(element):
- return element.tag[element.tag.rfind("}") + 1:]
+# Copyright (c) 2017 Ultimaker B.V. +# Cura is released under the terms of the AGPLv3 or higher. + +import xml.etree.ElementTree as ET + +from UM.VersionUpgrade import VersionUpgrade + + +class XmlMaterialUpgrader(VersionUpgrade): + def getXmlVersion(self, serialized): + data = ET.fromstring(serialized) + + # get format version + version = None + metadata = data.iterfind("./um:metadata/*") + for entry in metadata: + tag_name = entry.tag + if tag_name == "version": + try: + version = int(entry.text) + except Exception as e: + raise ValueError("Invalid version string '%s': %s" % (entry.text, e)) + break + if version is None: + raise RuntimeError("Missing version in metadata") + + # get setting version + if "version" in data.attrib: + setting_version = self._xmlVersionToSettingVersion(data.attrib["version"]) + else: + setting_version = self._xmlVersionToSettingVersion("1.2") + + if version is None: + raise RuntimeError("Missing version in metadata") + + return version * 1000000 + setting_version + + def _xmlVersionToSettingVersion(self, xml_version: str) -> int: + if xml_version == "1.3": + return 1 + return 0 #Older than 1.3. + + def upgradeMaterial(self, serialised, filename): + data = ET.fromstring(serialised) + + # update version + metadata = data.iterfind("./um:metadata/*", {"um": "http://www.ultimaker.com/material"}) + for entry in metadata: + if _tag_without_namespace(entry) == "version": + entry.text = "2" + break + + data.attrib["version"] = "1.3" + + # this makes sure that the XML header states encoding="utf-8" + new_serialised = ET.tostring(data, encoding="utf-8").decode("utf-8") + + return [filename], [new_serialised] + + +def _tag_without_namespace(element): + return element.tag[element.tag.rfind("}") + 1:] |