#!/usr/bin/env python import sys, os import bom, parts_db if len(sys.argv) < 2: print "Usage: %s DIR -N SCHEMATIC1 -M SCHEMATIC2 ..." % os.path.basename( sys.argv[0] ) print "Where N and M are multipliers for the number of boards" sys.exit(1) db = parts_db.Db( bom.PARTS_DB ) m = bom.MultiBoardBom(db) mul = 1 for fname in sys.argv[1:]: if fname[0] == '-': mul = int(fname[1:]) else: board = bom.BoardBom( db, fname, os.path.basename( fname ) ) m.add_boards(board, mul) mul = 1 # Group the parts by distributor: # Keys of ths dictionary are the distributor dist = {} for srcode, pg in m.iteritems(): if srcode == "sr-nothing": continue supplier = pg.part["supplier"] if not dist.has_key(supplier): dist[supplier] = [] dist[supplier].append( pg ) for d, partgroups in dist.iteritems(): print "Distributor: %s" % d for pg in partgroups: n = pg.order_num() if n == None: print "FAIL :-(" else: if d == "farnell": print "%s, %i" % ( pg.part["order-number"], pg.order_num() ) else: print " - %i * %s" % ( pg.order_num(), pg.part["order-number"] ) print "Total Price:", m.get_price()