diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-01-07 14:00:46 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-01-07 14:00:46 +0100 |
commit | 0958273a71dd19c2a90471a182ccc5b90b14e5b4 (patch) | |
tree | 8e33385ca9df94b80ce9b1f8ba06438b807f137a /trygvis/eda/cli/digikey_download_for_schematic.py | |
parent | 5d7fc9c4b14536006f2435b1379887f95937e096 (diff) | |
download | eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.tar.gz eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.tar.bz2 eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.tar.xz eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.zip |
Renaming 'schematic' to 'project'.
Renaming 'kicad-bom-to-ttl' to 'kicad-import-project'.
Renaming 'digikey-download-for-schematic' to 'digikey-download-for-project'.
Splitting out the Export xml file code into its own module.
init: putting project.url and project.file in config.ini.
init: putting db.update-url in config.ini if given on the command line.
kicad-import-project: by default, assume that the user want to update local database, optionally write the ttl file to disk.
cli.write_graph: create any missing parent directories.
Diffstat (limited to 'trygvis/eda/cli/digikey_download_for_schematic.py')
-rwxr-xr-x | trygvis/eda/cli/digikey_download_for_schematic.py | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/trygvis/eda/cli/digikey_download_for_schematic.py b/trygvis/eda/cli/digikey_download_for_schematic.py deleted file mode 100755 index bf4f0ce..0000000 --- a/trygvis/eda/cli/digikey_download_for_schematic.py +++ /dev/null @@ -1,87 +0,0 @@ -import rdflib -import rdflib.term - -from trygvis.eda import cli -from trygvis.eda.digikey import * - - -def work(schematic_url, force, g): - client = DigikeyClient() - db = DigikeyDatabase() - download_category_tree(db, client) - - # Dump schematic: - # SELECT ?schematic - # WHERE { - # ?schematic a kicad-type:schematic . - # b:rateboard-2_a ? ?. - # ?s ?predicate ?object . - # } - - # allComponentsQ = prepareQuery('SELECT ?ref ?value WHERE { ?schematic_url a kicad-type:schematic . ?schematic_url kicad:component ?o . ?o rdfs:label ?ref . ?o kicad:value ?value . }', initNs = initNs) - # - # for row in g.query(allComponentsQ, initBindings={'schematic_url': schematic_url}): - # print("ref=%s, value=%s" % (row.ref, row.value)) - - res = cli.sparql(g, "SELECT ?schematic WHERE {?schematic a kicad-type:schematic}") - print("Found %d schematics in database" % len(res)) - for row in res: - print("schematic: %s" % row.schematic) - - res = cli.sparql(g, "SELECT ?dk_part ?dk_part_number WHERE {?dk_part a dk:part ; dk:partNumber ?dk_part_number}") - print("Found %d Digikey parts in database" % len(res)) - for row in res: - print("Part: url=%s, partNumber=%s" % (row.dk_part, row.dk_part_number)) - - res = cli.sparql(g, """ -SELECT - ?digikey_pn - (group_concat(distinct ?ref;separator=";") as ?refs) -WHERE { - ?schematic_url kicad:component ?cmp . - ?cmp rdfs:label ?ref ; - kicad:value ?value . - OPTIONAL { - ?cmp kicad:field ?d . - ?d kicad:field_name "digikey" ; - kicad:field_value ?digikey_pn . - OPTIONAL { - ?dk_part a dk:part ; - dk:partNumber ?digikey_pn . - } - } -} -GROUP BY ?digikey_pn -ORDER BY ?digikey_pn -""", init_bindings={'schematic_url': rdflib.term.URIRef(schematic_url)}) - size = len(res) - - if size == 0: - cli.info('Could not find an parts for the schematic, did you use the correct URL: %s?' % schematic_url) - - for row in res: - pn = row.digikey_pn - - if pn is None: - continue - - refs = row.refs.split(';') - - cli.info("Part \"%s\" is used by %s" % (pn, refs)) - - filename = 'ttl/digikey-part-' + normalize_filename(pn + ".ttl") - - def download_graph(): - cli.info("Downloading product: " + pn) - product = download_product(client, db, pn) - - g = cli.create_graph(digikey=True) - [g.add(node) for node in product.to_nodes()] - return g - - 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, args.force, g)) |