Clarify, extend, and rename ky*.py to kicad_netlist_reader.py.

Significantly enhance the bom_csv_grouped_by_value.py BOM generator.
IMO it at this moment, the best BOM production tool for KiCad.
This commit is contained in:
Dick Hollenbeck
2013-09-01 12:49:01 -05:00
parent 4d1dc14b45
commit 3fcf44ae32
10 changed files with 897 additions and 514 deletions
+17 -11
View File
@@ -4,8 +4,10 @@
# Example: Sorted and Grouped HTML BOM with more advanced grouping
#
from __future__ import print_function
# Import the KiCad python helper module and the csv formatter
import ky_generic_netlist_reader
import kicad_netlist_reader
import sys
# Start with a basic html template
@@ -43,9 +45,9 @@ def myEqu(self, other):
result = True
if self.getValue() != other.getValue():
result = False
elif self.getLib() != other.getLib():
elif self.getLibName() != other.getLibName():
result = False
elif self.getPart() != other.getPart():
elif self.getPartName() != other.getPartName():
result = False
elif self.getFootprint() != other.getFootprint():
result = False
@@ -61,18 +63,18 @@ def myEqu(self, other):
# Override the component equivalence operator - it is important to do this
# before loading the netlist, otherwise all components will have the original
# equivalency operator.
ky_generic_netlist_reader.component.__equ__ = myEqu
kicad_netlist_reader.comp.__equ__ = myEqu
# Generate an instance of a generic netlist, and load the netlist tree from
# video.xml. If the file doesn't exist, execution will stop
net = ky_generic_netlist_reader.netlist(sys.argv[1])
net = kicad_netlist_reader.netlist(sys.argv[1])
# Open a file to write too, if the file cannot be opened output to stdout
# instead
try:
f = open(sys.argv[2], 'w')
except IOError:
print >> sys.stderr, __file__, ":", e
print(__file__, ":", e, file=sys.stderr)
f = stdout
# Output a set of rows for a header providing general information
@@ -90,9 +92,11 @@ row += "<th>PartNumber</th>" + "<th>Vendor</th></tr>"
html = html.replace('<!--TABLEROW-->', row + "<!--TABLEROW-->")
components = net.getInterestingComponents()
# Get all of the components in groups of matching parts + values
# (see ky_generic_netlist_reader.py)
grouped = net.groupComponents()
# (see kicad_netlist_reader.py)
grouped = net.groupComponents(components)
# Output all of the component information
for group in grouped:
@@ -101,12 +105,14 @@ for group in grouped:
# Add the reference of every component in the group and keep a reference
# to the component so that the other data can be filled in once per group
for component in group:
refs += component.getRef() + ", "
if len(refs) > 0:
refs += ", "
refs += component.getRef()
c = component
row = "<tr><td>" + refs +"</td><td>" + str(len(group))
row += "</td><td>" + c.getValue() + "</td><td>"
row += c.getLib() + "/" + c.getPart() + "</td><td>"
row += c.getLibName() + ":" + c.getPartName() + "</td><td>"
#row += c.getDatasheet() + "</td><td>"
row += c.getDescription() + "</td><td>"
row += c.getField("PartNumber") + "</td><td>"
@@ -116,4 +122,4 @@ for group in grouped:
html = html.replace('<!--TABLEROW-->', row + "<!--TABLEROW-->")
# Print the formatted html to output file
print >> f, html
print(html, file=f)