aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2017-09-24 09:46:21 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2017-09-24 09:46:21 +0200
commit930e3d61917bd4bf162142db64301691afdf9539 (patch)
treef2e06b6aef12026a5f99742ca78f178f63f5037b /src/ee/tools
parent33a03ca8cb65202509bd009832010f8f587ace47 (diff)
downloadee-python-930e3d61917bd4bf162142db64301691afdf9539.tar.gz
ee-python-930e3d61917bd4bf162142db64301691afdf9539.tar.bz2
ee-python-930e3d61917bd4bf162142db64301691afdf9539.tar.xz
ee-python-930e3d61917bd4bf162142db64301691afdf9539.zip
o Let digikey-download-facts read .sch files directly.
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/digikey_download_facts.py42
-rw-r--r--src/ee/tools/kicad_make_bom.py2
2 files changed, 25 insertions, 19 deletions
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: