aboutsummaryrefslogtreecommitdiff
path: root/trygvis/eda
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-12-28 16:37:39 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2017-01-05 09:24:41 +0100
commite92fb46ec42991dca60d22d8b1ab321b7c4ff146 (patch)
tree8eff3bf9472d4964098846fdbc8eb8d3438700bf /trygvis/eda
parent673dcbcab144a274bbc26a926d4a735275519b92 (diff)
downloadeda-rdf-e92fb46ec42991dca60d22d8b1ab321b7c4ff146.tar.gz
eda-rdf-e92fb46ec42991dca60d22d8b1ab321b7c4ff146.tar.bz2
eda-rdf-e92fb46ec42991dca60d22d8b1ab321b7c4ff146.tar.xz
eda-rdf-e92fb46ec42991dca60d22d8b1ab321b7c4ff146.zip
o Adding --force flag to digikey-download-for-schematic.
o Unbreaking download_product().
Diffstat (limited to 'trygvis/eda')
-rwxr-xr-xtrygvis/eda/cli/digikey_download_for_schematic.py6
-rwxr-xr-xtrygvis/eda/cli/digikey_download_metadata.py2
-rw-r--r--trygvis/eda/cli/eda_rdf.py3
-rwxr-xr-xtrygvis/eda/cli/make_bom.py2
-rw-r--r--trygvis/eda/digikey/__init__.py49
5 files changed, 36 insertions, 26 deletions
diff --git a/trygvis/eda/cli/digikey_download_for_schematic.py b/trygvis/eda/cli/digikey_download_for_schematic.py
index 4be2632..bf4f0ce 100755
--- a/trygvis/eda/cli/digikey_download_for_schematic.py
+++ b/trygvis/eda/cli/digikey_download_for_schematic.py
@@ -5,7 +5,7 @@ from trygvis.eda import cli
from trygvis.eda.digikey import *
-def work(schematic_url, g):
+def work(schematic_url, force, g):
client = DigikeyClient()
db = DigikeyDatabase()
download_category_tree(db, client)
@@ -79,9 +79,9 @@ ORDER BY ?digikey_pn
[g.add(node) for node in product.to_nodes()]
return g
- cli.write_graph(download_graph, filename)
+ cli.write_graph(download_graph, filename, force_write=force)
def run(schematic_url, args):
cli.info("Schematic: %s" % schematic_url)
- cli.with_database(lambda g: work(schematic_url, g))
+ cli.with_database(lambda g: work(schematic_url, args.force, g))
diff --git a/trygvis/eda/cli/digikey_download_metadata.py b/trygvis/eda/cli/digikey_download_metadata.py
index d807c1a..60880ab 100755
--- a/trygvis/eda/cli/digikey_download_metadata.py
+++ b/trygvis/eda/cli/digikey_download_metadata.py
@@ -41,5 +41,5 @@ def run(args):
for pc in db.productCategories:
for sc in pc.subCategories:
- output = "%s/digikey-%s.ttl" % (args.output_dir, normalize_filename(sc.label))
+ output = "%s/digikey-category-%s.ttl" % (args.output_dir, normalize_filename(sc.label))
do_category(client, sc, output)
diff --git a/trygvis/eda/cli/eda_rdf.py b/trygvis/eda/cli/eda_rdf.py
index 7b4ed2c..ee4b0dd 100644
--- a/trygvis/eda/cli/eda_rdf.py
+++ b/trygvis/eda/cli/eda_rdf.py
@@ -9,6 +9,8 @@ class CliCommand(object):
self.description = description
+# TODO: move all of the command classes to the file they delegate to.
+
class AddToDb(CliCommand):
def __init__(self):
super().__init__("add-to-db", "Import RDF triplet file to the database")
@@ -55,6 +57,7 @@ class DigikeyDownloadForSchematic(CliCommand):
def run(self, argv):
p = argparse.ArgumentParser(prog=self.key, description=self.description)
p.add_argument("--schematic", required=True)
+ p.add_argument("-f", "--force", default=False, action='store_true')
args = p.parse_args(argv)
from trygvis.eda.cli import digikey_download_for_schematic
diff --git a/trygvis/eda/cli/make_bom.py b/trygvis/eda/cli/make_bom.py
index fcdbe99..8d8c9f1 100755
--- a/trygvis/eda/cli/make_bom.py
+++ b/trygvis/eda/cli/make_bom.py
@@ -104,4 +104,4 @@ ORDER BY ?ref ?attr_type ?attr_value
part = dk_parts[pn]
part.set_attribute(row.type, row.value)
- cli.info('%5s: %-20s %s' % (pn, row.type + ':', row.value))
+ cli.info('%-30s %-50s %s' % (pn, row.type + ':', row.value))
diff --git a/trygvis/eda/digikey/__init__.py b/trygvis/eda/digikey/__init__.py
index ec1167d..8fe18c8 100644
--- a/trygvis/eda/digikey/__init__.py
+++ b/trygvis/eda/digikey/__init__.py
@@ -146,9 +146,9 @@ class DigikeyProduct(object):
nodes.append((node, rdf.DIGIKEY.partNumber, Literal(self.part_number)))
nodes.append((node, RDFS.label, Literal(self.description)))
for v in self.values:
- typeLabel = v.type.label if v.type is not None else v.typeLabel
- typeId = v.type.id if v.type is not None else v.typeId
- nodes.append((node, rdf.DIGIKEY['attribute-value'], rdf.DIGIKEY_ATTRIBUTE_VALUE[typeId + '-' + v.id]))
+ type_label = v.type.label if v.type is not None else v.type_label
+ type_id = v.type.id if v.type is not None else v.type_id
+ nodes.append((node, rdf.DIGIKEY['attribute-value'], rdf.DIGIKEY_ATTRIBUTE_VALUE[type_id + '-' + v.id]))
for c in self.categories:
nodes.append((node, rdf.DIGIKEY.category, c.url()))
@@ -255,42 +255,49 @@ def download_product(client: DigikeyClient, db, query):
values = []
categories = []
for table in tree.xpath("//table[contains(@class, 'attributes-table-main')]"):
- label = None
- id = None
for tr in table.xpath(".//tr"):
if tr.get("id") is not None:
continue
tds = tr.xpath("./th | ./td")
+ # print('tds: ' + str(tds))
+ # for x in tds:
+ # print(_to_string(x))
if len(tds) != 3:
continue
type_label = _to_string(tds[0])
label = _to_string(tds[1])
+
+ type_id = value = None
for input in tds[2].xpath("./input[@name]"):
- typeId = input.get("name")
- id = input.get("value")
- else:
- typeId = None
+ type_id = input.get("name")
+ value = input.get("value")
- if id is None or typeId is None:
+ if value is None or type_id is None:
continue
- if typeId == "t": # categories are handled later
+ if type_id == "t": # categories are handled later
continue
- values.append(DigikeyAttributeValue(id, label, type_id=typeId, type_label=type_label))
+ values.append(DigikeyAttributeValue(value, label, type_id=type_id, type_label=type_label))
for td in table.xpath(".//td[@class='attributes-td-categories-link']"):
tr = td.getparent()
- id = None
- url = None
- for a in td.xpath(".//a[@href]"):
- url = a.get("href")
- id = _id_from_url(url)
- for input in tr.xpath(".//input[@name='t' and @value]"):
- categoryId = input.get("value")
+ a = next((a for a in td.xpath(".//a[@href]")), None)
+ if a is None:
+ continue
+
+ label = "dummy" # a.text()
- if id is None:
+ url = a.get("href")
+ if url is None:
continue
- categories.append(DigikeyProductCategory(id, label, digikey_url=url))
+
+ value = _id_from_url(url)
+ if value is None:
+ continue
+
+ category_id = next((e.get("value") for e in tr.xpath(".//input[@name='t' and @value]")), None)
+
+ categories.append(DigikeyProductCategory(category_id, label, digikey_url=url))
part_id = part_number = None
for n in tree.xpath("//input[@name='partid' and @value]"):