Updated xml_writer

This commit is contained in:
Oliver 2016-05-15 16:13:06 +10:00
parent 2a94249047
commit 640e3d73f7
1 changed files with 23 additions and 30 deletions

View File

@ -18,41 +18,34 @@ def WriteXML(filename, groups, net, headings, prefs):
if not filename.endswith(".xml"): if not filename.endswith(".xml"):
return False return False
try: xml = ElementTree.Element('KiCAD_BOM', attrib = {
xml = ElementTree.Element('KiCAD_BOM', attrib = { 'source' : net.getSource(),
'source' : net.getSource(), 'version' : net.getVersion(),
'version' : net.getVersion(), 'date' : net.getDate(),
'date' : net.getDate(), 'groups' : str(len(groups)),
'groups' : str(len(groups)), 'components' : str(sum([group.getCount() for group in groups]))
'components' : str(sum([group.getCount() for group in groups])) })
})
for group in groups:
if prefs.ignoreDNF and not group.isFitted():
continue
row = group.getRow(headings)
for group in groups: attrib = {}
if prefs.ignoreDNF and not group.isFitted():
continue
row = group.getRow(headings)
attrib = {}
for i,h in enumerate(headings):
h = h.replace(' ','_') #replace spaces, xml no likey
h = h.replace('"','')
h = h.replace("'",'')
attrib[h] = row[i]
sub = ElementTree.SubElement(xml, "group", attrib=attrib)
with open(filename,"w") as output: for i,h in enumerate(headings):
out = ElementTree.tostring(xml, 'utf-8') h = h.replace(' ','_') #replace spaces, xml no likey
h = h.replace('"','')
h = h.replace("'",'')
output.write(minidom.parseString(out).toprettyxml(indent="\t")) attrib[h] = row[i]
return True sub = ElementTree.SubElement(xml, "group", attrib=attrib)
with open(filename,"w") as output:
out = ElementTree.tostring(xml, 'utf-8')
except BaseException as e: output.write(minidom.parseString(out).toprettyxml(indent="\t"))
print(str(e))
return False
return True return True