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)