Commit 17fc22a9 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

tools: add compare_BOM.py

parent fe3a9293
#! /usr/bin/env python3
import argparse
import pprint
import pandas
parser = argparse.ArgumentParser(description="Compare 2 BOMs in ODF format (dumped by Altium in Excel and then converted to ods)")
parser.add_argument('ref_BOM')
parser.add_argument('new_BOM')
args = parser.parse_args()
pp = pprint.PrettyPrinter(indent=4)
def read_line_eof(f):
l = f.readline()
if len(l) == 0:
raise EOFError
return l.strip()
def read_BOM(f):
c = {}
bom = pandas.read_excel(f, engine="odf")
#print(bom)
for index, row in bom.iterrows():
infos = {
'value': row["Value"],
'infos': row["Infos"]
}
for comp in row["Designator"].split(','):
c[comp] = infos
return c
def dict_compare(d1, d2):
d1_keys = set(d1.keys())
d2_keys = set(d2.keys())
shared_keys = d1_keys.intersection(d2_keys)
added = d2_keys - d1_keys
removed = d1_keys - d2_keys
modified = {o : (d1[o], d2[o]) for o in shared_keys if d1[o] != d2[o]}
same = set(o for o in shared_keys if d1[o] == d2[o])
return added, removed, modified, same
def pprint(o):
if len(o) > 0:
pp.pprint(o)
else:
print(None)
def compare_netlist(BOM_ref, BOM_new):
comp_added, comp_removed, comp_modified, comp_same = dict_compare(BOM_ref, BOM_new)
print("******************************************************")
print("******************************************************")
print("Added in BOM:")
pprint(comp_added)
print("Removed in BOM:")
pprint(comp_removed)
print("Modified in BOM:")
pprint(comp_modified)
compare_netlist(read_BOM(args.ref_BOM), read_BOM(args.new_BOM))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment