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) bom = generate_bom(args.allow_incomplete, bom_parts, supplier_parts) enable_value = False if bom is not None: with out_path.open("w") as f: w = csv.writer(f) fields = ["Part URI", "Description", "MPN", "SPN", "Quantity", "References"] if enable_value: fields.append("Value") w.writerow(fields) for line in bom.lines: mpn = line.part.get_only_mpn() spn = line.part.get_only_spn() row = [ line.part.uri, line.part.description, mpn.valueProp if mpn else "", spn.valueProp if spn else "", str(len(line.refs)), join_refs(line.refs), ] if enable_value: value = "" # line.part.facts.get_value() row.append(value) w.writerow(row)