#!/usr/bin/env python import os, sys, parts_db, bom, schem if len(sys.argv) < 2: print "Usage: %s SCHEMATIC" % os.path.basename(sys.argv[0]) print "Checks that all the parts in a PCB's schematic are in the SR database" sys.exit(1) SCHEMATIC = sys.argv[1] lib = parts_db.Db(bom.PARTS_DB) parts = schem.open_schem(SCHEMATIC) bom = {} error = 0 found = 0 # Erroneous parts (key is type) err_parts = {} for id in parts.keys(): if not lib.has_key( parts[id] ): if not err_parts.has_key(parts[id]): err_parts[parts[id]] = [] err_parts[parts[id]].append(id) error = error + 1 else: found = found + 1 print "%i correct parts found." % found if len(err_parts) > 0: print "The following %i parts are not in the SR parts database:" % error for name, components in err_parts.iteritems(): print "\t'%s': %s" % (name, " ".join(components)) sys.exit(2)