#!/usr/bin/env python import os, sys, time, parts_db, bom def html_header(f): f.write(""" Student Robotics Bill of Materials for ...

Generated on %s with %s.

""" % (time.asctime(), os.path.basename(sys.argv[0])) ) def html_footer(f): f.write("""""") if len(sys.argv) < 3: print "Usage: %s SCHEMATIC OUTFILE" % (os.path.basename(sys.argv[0])) print "Where:" print " - SCHEMATIC is the schematic to read from" print " - OUTFILE is the output HTML file" sys.exit(1) [SCHEMATIC, OUTFILE] = sys.argv[1:3] schem_name = os.path.basename( SCHEMATIC ) lib = parts_db.Db(bom.PARTS_DB) parts = bom.BoardBom(lib, SCHEMATIC, schem_name) outf = open( OUTFILE, "w" ) html_header(outf) def srcode_sort(x,y): return cmp(x.part["sr-code"], y.part["sr-code"]) lines = parts.values() lines.sort(srcode_sort) for line in lines: outf.write("") p = line.part if p["sr-code"] == "sr-nothing": "Ignore sr-nothing -- we don't want it in HTML BOMs" continue for x in [ p["sr-code"], p["description"], p["supplier"], p["order-number"], len(line), ", ".join([x[1] for x in line]) ]: outf.write("" % x) outf.write("") html_footer(outf)
srcode Description Distributer Distributor Order Number Quantity Designators
%s