diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-14 21:42:18 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-06-14 21:42:18 +0200 |
commit | b4eeed35d78f82ea988d70de177d522ca20257ea (patch) | |
tree | f5db959036edee3c292e906d1ac40a66bd8c2e2b /src/ee/tools | |
parent | 89197dad4f5f427faa7fba12971b20037ad5ba71 (diff) | |
download | ee-python-b4eeed35d78f82ea988d70de177d522ca20257ea.tar.gz ee-python-b4eeed35d78f82ea988d70de177d522ca20257ea.tar.bz2 ee-python-b4eeed35d78f82ea988d70de177d522ca20257ea.tar.xz ee-python-b4eeed35d78f82ea988d70de177d522ca20257ea.zip |
bom-to-csv: Starting on a generic tool to generate CSV files from BOMs.
Diffstat (limited to 'src/ee/tools')
-rw-r--r-- | src/ee/tools/bom_to_csv.py | 55 | ||||
-rw-r--r-- | src/ee/tools/digikey_create_bom.py | 6 | ||||
-rw-r--r-- | src/ee/tools/templates/build.ninja.j2 | 9 |
3 files changed, 62 insertions, 8 deletions
diff --git a/src/ee/tools/bom_to_csv.py b/src/ee/tools/bom_to_csv.py new file mode 100644 index 0000000..181eb4e --- /dev/null +++ b/src/ee/tools/bom_to_csv.py @@ -0,0 +1,55 @@ +import argparse +import csv +from pathlib import Path + +import ee.tools +from ee.part.bom import load_bom, check_bom, generate_bom, join_refs + +parser = argparse.ArgumentParser() +ee.tools.add_default_argparse_group(parser) + +parser.add_argument("--bom", + required=True, + metavar="PART DB") + +parser.add_argument("--out", + required=True, + metavar="CSV") + +parser.add_argument("--part-db", + nargs="*", + required=True, + metavar="PART DB") + +parser.add_argument("--allow-incomplete", + default=False, + action="store_true") + +args = parser.parse_args() +ee.tools.process_default_argparse_group(args) + +bom_path = Path(args.bom) +part_files = [Path(p) for p in args.part_db] +out_path = Path(args.out) + +bom_parts, supplier_parts = load_bom(bom_path, part_files) +check_bom(bom_parts, supplier_parts) + +lines = generate_bom(args.allow_incomplete, bom_parts, supplier_parts) + +if lines is not None: + with out_path.open("w") as f: + w = csv.writer(f) + w.writerow(["Quantity", "MPN", "SPN", "References"]) + + for line in lines: + mpn = line.part.get_only_mpn() + spn = line.part.get_only_spn() + + row = [ + str(len(line.refs)), + mpn.valueProp if mpn else "", + spn.valueProp if spn else "", + join_refs(line.refs), + ] + w.writerow(row) diff --git a/src/ee/tools/digikey_create_bom.py b/src/ee/tools/digikey_create_bom.py index a83da83..eaea121 100644 --- a/src/ee/tools/digikey_create_bom.py +++ b/src/ee/tools/digikey_create_bom.py @@ -20,14 +20,10 @@ parser.add_argument("--part-db", required=True, metavar="PART DB") -parser.add_argument("--store", - default="us", - metavar="STORE CODE") - parser.add_argument("--allow-incomplete", action="store_true") args = parser.parse_args() ee.tools.process_default_argparse_group(args) -create_bom(Path(args.bom), [Path(p) for p in args.part_db], Path(args.out), args.store, args.allow_incomplete) +create_bom(Path(args.bom), [Path(p) for p in args.part_db], Path(args.out), args.allow_incomplete) diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2 index 1ab6102..016c7da 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -12,12 +12,15 @@ pcb = {{ pcb | ninja_path }} {%- endif %} {%- set log=log if log is defined else "--log=warn" %} -rule kicad-gerber - command = $ee kicad-gerber --pcb $in --output-dir $dir --index $out - rule mkzip command = $ee mkzip --include $in --zip $out +rule bom-to-csv + command = $ee bom-to-csv {{ log }} --bom $in --out $out $part_dbs $args + +rule kicad-gerber + command = $ee kicad-gerber --pcb $in --output-dir $dir --index $out + rule kicad-make-bom command = $ee kicad-make-bom {{ log }} --sch $sch --out $out --uuid $uuid |