Make some minor improvements to the xml reader

This commit is contained in:
Veronica Berglyd Olsen
2022-11-05 21:37:10 +01:00
parent 72cc0cf0aa
commit 9cdf840d12
+11 -11
View File
@@ -347,8 +347,8 @@ class ProjectXMLReader:
# Deprecated Nodes # Deprecated Nodes
if self._version < HEX_VERSION: if self._version < HEX_VERSION:
for xVal in xItem: for xVal in xItem:
if xVal.tag == "name": if xVal.tag == "name" and "exported" in xVal.attrib:
name["active"] = checkBool(xVal.attrib.get("exported"), name["active"]) name["active"] = checkBool(xVal.attrib.get("exported"), False)
projContent.append({ projContent.append({
"name": itemName, "name": itemName,
@@ -365,16 +365,19 @@ class ProjectXMLReader:
logger.debug("Parsing <content> section (legacy format)") logger.debug("Parsing <content> section (legacy format)")
# Create maps to look up name -> key for status and importance # Create maps to look up name -> key for status and importance
statusMap = {entry["name"]: key for key, entry in projData.itemStatus.items()} statusMap = {entry.get("name"): key for key, entry in projData.itemStatus.items()}
importMap = {entry["name"]: key for key, entry in projData.itemImport.items()} importMap = {entry.get("name"): key for key, entry in projData.itemImport.items()}
for xItem in xSection: for xItem in xSection:
if xItem.tag != "item":
logger.warning("Ignored item <root/content/%s> in XML", xItem.tag)
continue
item = {} item = {}
meta = {} meta = {}
name = {} name = {}
itemName = "" itemName = ""
if xItem.tag == "item":
item["handle"] = checkStringNone(xItem.attrib.get("handle", None), None) item["handle"] = checkStringNone(xItem.attrib.get("handle", None), None)
item["parent"] = checkStringNone(xItem.attrib.get("parent", None), None) item["parent"] = checkStringNone(xItem.attrib.get("parent", None), None)
item["root"] = None # Value was added in 1.4 item["root"] = None # Value was added in 1.4
@@ -395,7 +398,7 @@ class ProjectXMLReader:
item["layout"] = checkString(xVal.text, "") item["layout"] = checkString(xVal.text, "")
elif xVal.tag == "expanded": elif xVal.tag == "expanded":
meta["expanded"] = checkBool(xVal.text, False) meta["expanded"] = checkBool(xVal.text, False)
elif xVal.tag == "exported": # Renamed to active in 1.4 elif xVal.tag == "exported": # Renamed to active in 1.5
name["active"] = checkBool(xVal.text, False) name["active"] = checkBool(xVal.text, False)
elif xVal.tag == "charCount": elif xVal.tag == "charCount":
meta["charCount"] = checkInt(xVal.text, 0) meta["charCount"] = checkInt(xVal.text, 0)
@@ -420,7 +423,7 @@ class ProjectXMLReader:
): ):
item["layout"] = "DOCUMENT" item["layout"] = "DOCUMENT"
# The trast type was removed in 1.4 # The trash type was removed in 1.4
if item.get("type", "") == "TRASH": if item.get("type", "") == "TRASH":
item["type"] = "ROOT" item["type"] = "ROOT"
@@ -431,9 +434,6 @@ class ProjectXMLReader:
"nameAttr": name, "nameAttr": name,
}) })
else:
logger.warning("Ignored <root/content/%s> in XML", xItem.tag)
return return
def _parseStatusImport(self, xItem, sObject): def _parseStatusImport(self, xItem, sObject):
@@ -463,7 +463,7 @@ class ProjectXMLReader:
"""Parse a dictionary stored with key as the tag and the value """Parse a dictionary stored with key as the tag and the value
as the text porperty. as the text porperty.
""" """
return {n.tag: checkString(n.text, "") for n in xItem} return {xNode.tag: checkString(xNode.text, "") for xNode in xItem}
# END Class ProjectXMLReader # END Class ProjectXMLReader