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"):
return False
try:
xml = ElementTree.Element('KiCAD_BOM', attrib = {
'source' : net.getSource(),
'version' : net.getVersion(),
'date' : net.getDate(),
'groups' : str(len(groups)),
'components' : str(sum([group.getCount() for group in groups]))
})
xml = ElementTree.Element('KiCAD_BOM', attrib = {
'source' : net.getSource(),
'version' : net.getVersion(),
'date' : net.getDate(),
'groups' : str(len(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:
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)
attrib = {}
with open(filename,"w") as output:
out = ElementTree.tostring(xml, 'utf-8')
for i,h in enumerate(headings):
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:
print(str(e))
return False
output.write(minidom.parseString(out).toprettyxml(indent="\t"))
return True