XML output is (kind of) working. Needs beautification
This commit is contained in:
parent
f1e75463f6
commit
9b4a819070
|
|
@ -1,6 +1,7 @@
|
||||||
import csv
|
import csv
|
||||||
import columns
|
import columns
|
||||||
from component import *
|
from component import *
|
||||||
|
from xml.etree import ElementTree
|
||||||
|
|
||||||
import os, shutil
|
import os, shutil
|
||||||
|
|
||||||
|
|
@ -11,6 +12,51 @@ def TmpFileCopy(filename):
|
||||||
|
|
||||||
if os.path.exists(filename) and os.path.isfile(filename):
|
if os.path.exists(filename) and os.path.isfile(filename):
|
||||||
shutil.copyfile(filename, filename + ".tmp")
|
shutil.copyfile(filename, filename + ".tmp")
|
||||||
|
|
||||||
|
def WriteXML(filename, groups, source, version, date, headings = columns.ColumnList._COLUMNS_ALL, ignore=[], ignoreDNF = False):
|
||||||
|
|
||||||
|
filename = os.path.abspath(filename)
|
||||||
|
|
||||||
|
if not filename.endswith(".xml"):
|
||||||
|
return False
|
||||||
|
|
||||||
|
headings = [h for h in headings if h not in ignore]
|
||||||
|
|
||||||
|
try:
|
||||||
|
TmpFileCopy(filename)
|
||||||
|
|
||||||
|
xml = ElementTree.Element('"KiCAD Bom"', attrib = {
|
||||||
|
'"source"' : source,
|
||||||
|
'"version"' : version,
|
||||||
|
'"date"' : date,
|
||||||
|
'"groups"' : str(len(groups)),
|
||||||
|
'"components"' : str(sum([group.getCount() for group in groups]))
|
||||||
|
})
|
||||||
|
|
||||||
|
for group in groups:
|
||||||
|
row = group.getKicadRow(headings)
|
||||||
|
|
||||||
|
attrib = {}
|
||||||
|
|
||||||
|
for i,h in enumerate(headings):
|
||||||
|
attrib['"' + h + '"'] = row[i]
|
||||||
|
|
||||||
|
sub = ElementTree.SubElement(xml, "group", attrib=attrib)
|
||||||
|
|
||||||
|
#write the document
|
||||||
|
tree = ElementTree.ElementTree(xml)
|
||||||
|
|
||||||
|
tree.write(filename)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except BaseException as e:
|
||||||
|
print(str(e))
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def WriteCSV(filename, groups, source, version, date, headings = columns.ColumnList._COLUMNS_ALL, ignore=[], ignoreDNF=False, numberRows=True):
|
def WriteCSV(filename, groups, source, version, date, headings = columns.ColumnList._COLUMNS_ALL, ignore=[], ignoreDNF=False, numberRows=True):
|
||||||
|
|
||||||
|
|
@ -22,7 +68,7 @@ def WriteCSV(filename, groups, source, version, date, headings = columns.ColumnL
|
||||||
elif filename.endswith(".tsv") or filename.endswith(".txt"):
|
elif filename.endswith(".tsv") or filename.endswith(".txt"):
|
||||||
delimiter = "\t"
|
delimiter = "\t"
|
||||||
else:
|
else:
|
||||||
return
|
return False
|
||||||
|
|
||||||
headings = [h for h in headings if h not in ignore] #copy across the headings
|
headings = [h for h in headings if h not in ignore] #copy across the headings
|
||||||
|
|
||||||
|
|
@ -71,10 +117,10 @@ def WriteCSV(filename, groups, source, version, date, headings = columns.ColumnL
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
except NameError:
|
|
||||||
pass
|
except BaseException as e:
|
||||||
# except BaseException as e:
|
print(str(e))
|
||||||
# print(str(e))
|
return False
|
||||||
|
|
||||||
return False
|
return True
|
||||||
|
|
||||||
Loading…
Reference in New Issue