Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

Commit

Permalink
Created initial script- needs more testing
Browse files Browse the repository at this point in the history
  • Loading branch information
scholvat committed Aug 23, 2017
1 parent 9202e69 commit 13f3e2d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
47 changes: 47 additions & 0 deletions bom/generate_warg_bom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import sys, os
import xml.etree.ElementTree as ET
import csv

def main():
if(len(sys.argv) != 3):
print "Make sure there are only 2 arguments!" #The user passes 2 arguments and the 1st argument is always the script filepath
filepath, input_filename, output_filename = sys.argv
output_filename += ".csv"

#get filename for component library
component_lib_filename = os.path.join(os.path.dirname(filepath), os.pardir, 'component_library.csv')

#output_dict stores the data to be written to csv
#found_parts is used to quickly find what index a component is at in the output_dict
output_dict = []
found_parts = []

#parse xml netlist
tree = ET.parse(input_filename)
root = tree.getroot()

#find all part numbers
for field in root.findall(".//*[@name='part_num']"):
if field.text not in found_parts:
found_parts.append(field.text)
output_dict.append({"part_num":field.text,
"quantity":1})
else:
output_dict[found_parts.index(field.text)]["quantity"] +=1

reader = csv.DictReader(open(component_lib_filename, 'rb'))
component_library = []
for line in reader:
if line["part_num"] in found_parts:
#add the extra information from the component library
output_dict[found_parts.index(line["part_num"])].update(line)

#write the csv
with open(output_filename, 'wb') as output_file:
dict_writer = csv.DictWriter(output_file, output_dict[0].keys())
dict_writer.writeheader()
dict_writer.writerows(output_dict)
print "wrote to {} file.".format(output_filename)

if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions component_library.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
WARG-part-#,Distrubuter,Distributer #,description,Manufacturer Part #,Inventory,Inventory Date,Alternative distributer #s,cost (qty. 1 CAD),Value,Footprint,link
part_num,Distrubuter,Distributer #,description,Manufacturer Part #,Inventory,Inventory Date,Alternative distributer #s,cost (qty. 1 CAD),Value,Footprint,link
CAPP-001,Digi-Key,1276-1119-1-ND ,CAP CER 10UF 6.3V X5R 0603,,31,6/18/17,445-7492-1-ND / 490-3896-1-ND / 445-4112-1-ND,,,,
CAPP-002,Digi-Key,1276-1104-1-ND,CAP CER 0.022UF 50V 10% X7R 0603,,100,6/18/17,,,,,
CAPP-003,Digi-Key,1276-6504-1-ND,CAP CER 22UF 10V X5R 0603,,0,6/18/17,,,,,
Expand Down Expand Up @@ -62,4 +62,4 @@ CAPP-008,,587-2909-1-ND,CAP CER 2.2UF 25V 10% X5R 0603,,99,6/18/17,,,,,
CAPP-004,,587-1262-1-ND,CAP CER 1.0UF 16V Y5V 0603,,90,6/18/17,,,,,
CAPP-005,,490-3285-1-ND,CAP CER .1UF 100V X7R 0603,,1,6/18/17,,,,,
CAPP-004,,399-5090-1-ND,CAP CERAMIC 1.00UF 16V X5R 0603,,83,6/18/17,,,,,
RESS-003,,311-100KGRCT-ND,RES SMD 100K OHM 5% 1/10W 0603,,100,6/18/17,,,,,
RESS-003,,311-100KGRCT-ND,RES SMD 100K OHM 5% 1/10W 0603,,100,6/18/17,,,,,

0 comments on commit 13f3e2d

Please sign in to comment.