From 930e3d61917bd4bf162142db64301691afdf9539 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 24 Sep 2017 09:46:21 +0200 Subject: o Let digikey-download-facts read .sch files directly. --- src/ee/tools/digikey_download_facts.py | 42 +++++++++++++++++++--------------- src/ee/tools/kicad_make_bom.py | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-) (limited to 'src/ee/tools') diff --git a/src/ee/tools/digikey_download_facts.py b/src/ee/tools/digikey_download_facts.py index c97ba9d..0550c5f 100644 --- a/src/ee/tools/digikey_download_facts.py +++ b/src/ee/tools/digikey_download_facts.py @@ -1,8 +1,6 @@ import argparse from itertools import * -import os.path -import yaml from colors import color import ee.digikey as dk @@ -11,11 +9,6 @@ from ee.tools import mk_parents parser = argparse.ArgumentParser(description="Download facts about parts from Digi-Key") -parser.add_argument("parts", - metavar="PART", - nargs="+", - help="The parts to download fact for") - parser.add_argument("--out", required=True, metavar="OUTPUT_DIRECTORY", @@ -23,6 +16,12 @@ parser.add_argument("--out", action="store", help="A directory to store fact files") +parser.add_argument("--part", + nargs="+", + help="the parts to download fact for") + +parser.add_argument("--sch") + parser.add_argument("--force", dest="force", action="store", @@ -32,26 +31,33 @@ args = parser.parse_args() digikey = dk.Digikey() client = dk.DigikeyClient(digikey, on_download=lambda s: print(color(s, 'grey'))) +repo = dk.DigikeyRepository(args.out) -def mpn_to_path(mpn): - return "{}/{}.yaml".format(args.out, mpn) +def on_product(product: DigikeyProduct): + repo.save(product) -def on_product(product: DigikeyProduct): - y = product.to_yaml() +parts = [] - filename = mpn_to_path(product.mpn) - mk_parents(filename) - with open(filename, "w") as f: - yaml.dump(y, f, encoding="utf-8", allow_unicode=True) +if args.part: + parts.append(args.part) +if args.sch: + from ee.kicad import read_schematic, to_bom + sch = read_schematic(args.sch) + for c in to_bom(sch): + digikey = c.get_field("digikey") + if digikey: + parts.append(digikey.value) + mpn = c.get_field("mpn") + if mpn: + parts.append(mpn.value) -for p in args.parts: +for p in parts: print(color("Searching for {}".format(p), "white")) - path = mpn_to_path(p) - if os.path.isfile(path) and not args.force: + if repo.has_product(p) and not args.force: continue response = client.search(p) diff --git a/src/ee/tools/kicad_make_bom.py b/src/ee/tools/kicad_make_bom.py index 518cf75..7d25799 100644 --- a/src/ee/tools/kicad_make_bom.py +++ b/src/ee/tools/kicad_make_bom.py @@ -23,7 +23,7 @@ args = parser.parse_args() sch = kicad.read_schematic(args.sch) -bom = kicad.to_bom(sch) +bom = kicad.to_bom_xml(sch) xml = ElementTree.tostring(bom, encoding='unicode') if args.pretty: -- cgit v1.2.3