Commit 4e2f9f63 authored by Thomas Gambier's avatar Thomas Gambier

Add netlist comparator

parent fb3dc63f
...@@ -38,6 +38,7 @@ In order to do a full functional product, you will need all those components: ...@@ -38,6 +38,7 @@ In order to do a full functional product, you will need all those components:
* `NC Drill`: text file for drilling * `NC Drill`: text file for drilling
* `Pick Place`: text files for pick and place * `Pick Place`: text files for pick and place
* `Schematic Print`: PDF version of the schematic * `Schematic Print`: PDF version of the schematic
* `tools`: directory containing useful tools
## FAQ ## FAQ
......
#! /usr/bin/env python3
import argparse
import pprint
parser = argparse.ArgumentParser(description="Compare 2 netlists dumped by Altium")
parser.add_argument('ref_netlist', type=argparse.FileType('r', encoding="ISO-8859-1"))
parser.add_argument('new_netlist', type=argparse.FileType('r', encoding="ISO-8859-1"))
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_netlist(f):
component_dict = {}
connection_dict = {}
line = read_line_eof(f)
try:
while True:
if line == "[":
component = read_line_eof(f)
component_dict[component] = []
line = read_line_eof(f)
while line != "]":
component_dict[component].append(line)
line = read_line_eof(f)
elif line == "(":
connection = read_line_eof(f)
connection_dict[connection] = []
line = read_line_eof(f)
while line != ")":
connection_dict[connection].append(line)
line = read_line_eof(f)
connection_dict[connection].sort()
else:
line = read_line_eof(f)
except EOFError:
return (component_dict, connection_dict)
return (component_dict, connection_dict)
def dict_compare(d1, d2):
d1_keys = set(d1.keys())
d2_keys = set(d2.keys())
shared_keys = d1_keys.intersection(d2_keys)
added = d1_keys - d2_keys
removed = d2_keys - d1_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(netlist1, netlist2):
comp1, con1 = netlist1
comp2, con2 = netlist2
comp_added, comp_removed, comp_modified, comp_same = dict_compare(comp2, comp1)
con_added, con_removed, con_modified, con_same = dict_compare(con2, con1)
print("******************************************************")
print("******************** COMPONENTS **********************")
print("******************************************************")
print("Added in netlist:")
pprint(comp_added)
print("Removed in netlist:")
pprint(comp_removed)
print("Modified in netlist:")
pprint(comp_modified)
print("\n\n")
print("******************************************************")
print("*********************** NETS *************************")
print("******************************************************")
print("Added in netlist:")
pprint(con_added)
print("Removed in netlist:")
pprint(con_removed)
print("Modified in netlist:")
for c in con_modified:
l1,l2 = con_modified[c]
print("")
print("NET: {}".format(c))
print("Wires added:", end='')
s = set(l1) - set(l2)
if len(s) > 0:
print(s)
else:
print("None")
print("Wires removed:", end='')
s = set(l2) - set(l1)
if len(s) > 0:
print(s)
else:
print("None")
compare_netlist(read_netlist(args.ref_netlist), read_netlist(args.new_netlist))
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