first pass at html exporter
This commit is contained in:
parent
9b4a819070
commit
214c3ab297
|
|
@ -13,6 +13,14 @@ 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 link(text):
|
||||||
|
text = str(text)
|
||||||
|
for t in ["http","https","ftp","www"]:
|
||||||
|
if text.startswith(t):
|
||||||
|
return '<a href="{t}">{t}</a>'.format(t=text)
|
||||||
|
|
||||||
|
return text
|
||||||
|
|
||||||
def WriteXML(filename, groups, source, version, date, headings = columns.ColumnList._COLUMNS_ALL, ignore=[], ignoreDNF = False):
|
def WriteXML(filename, groups, source, version, date, headings = columns.ColumnList._COLUMNS_ALL, ignore=[], ignoreDNF = False):
|
||||||
|
|
||||||
filename = os.path.abspath(filename)
|
filename = os.path.abspath(filename)
|
||||||
|
|
@ -56,6 +64,73 @@ def WriteXML(filename, groups, source, version, date, headings = columns.ColumnL
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def WriteHTML(filename, groups, net, headings = columns.ColumnList._COLUMNS_ALL, ignore=[], ignoreDNF=False, numberRows=True):
|
||||||
|
|
||||||
|
filename = os.path.abspath(filename)
|
||||||
|
|
||||||
|
headings = [h for h in headings if not h in ignore]
|
||||||
|
|
||||||
|
try:
|
||||||
|
TmpFileCopy(filename)
|
||||||
|
|
||||||
|
with open(filename,"w") as html:
|
||||||
|
|
||||||
|
#header
|
||||||
|
html.write("<html>\n")
|
||||||
|
html.write("<body>\n")
|
||||||
|
|
||||||
|
#PCB info
|
||||||
|
html.write("<h2>PCB Information</h2>\n")
|
||||||
|
html.write("<br>Source File: {source}\n".format(source=net.getSource()))
|
||||||
|
html.write("<br>Date: {date}\n".format(date=net.getDate()))
|
||||||
|
html.write("<br>Version: {version}\n".format(version=net.getVersion()))
|
||||||
|
html.write("<br>\n")
|
||||||
|
html.write("<h2>Component Groups</h2>\n")
|
||||||
|
|
||||||
|
#component groups
|
||||||
|
html.write('<table border="1">\n')
|
||||||
|
|
||||||
|
#row titles:
|
||||||
|
html.write("<tr>\n")
|
||||||
|
if numberRows:
|
||||||
|
html.write("\t<th></th>\n")
|
||||||
|
for h in headings:
|
||||||
|
html.write("\t<th>{h}</th>\n".format(h=h))
|
||||||
|
html.write("</tr>\n")
|
||||||
|
|
||||||
|
rowCount = 0
|
||||||
|
|
||||||
|
for i,group in enumerate(groups):
|
||||||
|
|
||||||
|
if ignoreDNF and not group.isFitted(): continue
|
||||||
|
|
||||||
|
row = group.getKicadRow(headings)
|
||||||
|
|
||||||
|
rowCount += 1
|
||||||
|
|
||||||
|
if numberRows:
|
||||||
|
row = [rowCount] + row
|
||||||
|
|
||||||
|
html.write("<tr>\n")
|
||||||
|
|
||||||
|
for r in row:
|
||||||
|
html.write("\t<td>{val}</td>\n".format(val=link(r)))
|
||||||
|
|
||||||
|
|
||||||
|
html.write("</tr>\n")
|
||||||
|
|
||||||
|
html.write("</table>\n")
|
||||||
|
|
||||||
|
html.write("</body></html>")
|
||||||
|
|
||||||
|
|
||||||
|
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):
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,10 @@ class ColumnList:
|
||||||
_COLUMNS_ALL = [
|
_COLUMNS_ALL = [
|
||||||
Column.COL_DESCRIPTION,
|
Column.COL_DESCRIPTION,
|
||||||
Column.COL_PART,
|
Column.COL_PART,
|
||||||
Column.COL_PART_LIB,
|
|
||||||
Column.COL_REFERENCE,
|
Column.COL_REFERENCE,
|
||||||
Column.COL_VALUE,
|
Column.COL_VALUE,
|
||||||
Column.COL_FP,
|
Column.COL_FP,
|
||||||
Column.COL_FP_LIB,
|
Column.COL_GRP_QUANTITY,
|
||||||
Column.COL_DATASHEET
|
Column.COL_DATASHEET
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class Component():
|
||||||
#simple string comparison
|
#simple string comparison
|
||||||
if self.getValue().lower() == other.getValue().lower(): return True
|
if self.getValue().lower() == other.getValue().lower(): return True
|
||||||
|
|
||||||
#otherwise, perform a more complicate value comparison
|
#otherwise, perform a more complicated value comparison
|
||||||
if units.compareValues(self.getValue(), other.getValue()): return True
|
if units.compareValues(self.getValue(), other.getValue()): return True
|
||||||
|
|
||||||
#no match, return False
|
#no match, return False
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue