From a00dcfc7f6d12442fca8c5b7d43f12b707f0c877 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 9 Apr 2019 06:03:33 +0200 Subject: o Renaming part-create-distributor-search-list to pn-part-search-list. Making the search more narrow, it is only responsible to find parts based on MPN or SPN. --- src/ee/part/__init__.py | 11 ++++++ src/ee/part/create_distributor_search_list.py | 44 ---------------------- src/ee/part/pn_part_search_list.py | 44 ++++++++++++++++++++++ src/ee/tools/ninja.py | 4 +- .../tools/part_create_distributor_search_list.py | 19 ---------- src/ee/tools/pn_part_search_list.py | 23 +++++++++++ src/ee/tools/templates/build.ninja.j2 | 31 +++++++++------ 7 files changed, 100 insertions(+), 76 deletions(-) delete mode 100644 src/ee/part/create_distributor_search_list.py create mode 100644 src/ee/part/pn_part_search_list.py delete mode 100644 src/ee/tools/part_create_distributor_search_list.py create mode 100644 src/ee/tools/pn_part_search_list.py diff --git a/src/ee/part/__init__.py b/src/ee/part/__init__.py index 7a58f75..fbf0838 100644 --- a/src/ee/part/__init__.py +++ b/src/ee/part/__init__.py @@ -56,6 +56,17 @@ class Part(object): def get_part_references(self) -> List[types.PartReference]: return self.xml.referencesProp.part_referenceProp + def get_exactly_one_part_reference(self) -> types.PartReference: + refs = self.get_part_references() + if len(refs) == 0: + raise EeException("This part does not contain any part references{}". + format(", uri=" + self.uri if self.uri else "")) + if len(refs) != 1: + raise EeException("This part does not contain exactly one part reference: {}". + format(", ".join([ref.part_uriProp for ref in refs]))) + + return refs[0] + # Schematic references def add_schematic_reference(self, ref): diff --git a/src/ee/part/create_distributor_search_list.py b/src/ee/part/create_distributor_search_list.py deleted file mode 100644 index 8d70e3e..0000000 --- a/src/ee/part/create_distributor_search_list.py +++ /dev/null @@ -1,44 +0,0 @@ -from pathlib import Path - -from ee.part import PartDb, load_db, save_db, Part, fact_keys -from ee.xml import types - -__all__ = ["create_distributor_search_list"] - -ignored_part_classes = [ - "mechanical" -] - - -def create_distributor_search_list(in_path: Path, out_path: Path): - in_parts = load_db(in_path) - out_parts = PartDb() - - print("loaded {} existing parts".format(in_parts.size())) - - for xml in in_parts.iterparts(): - part = Part(xml) - pn_value = next((p.valueProp for p in part.get_mpns()), None) - - part_class = part.find_fact(fact_keys.part_class) - if part_class: - if part_class.valueProp in ignored_part_classes: - continue - - if pn_value is None: - refs = [ref.referenceProp for ref in part.get_schematic_references()] - print("Skipping part with no part number: schematic reference: {}".format(", ".join(refs))) - continue - - entry = out_parts.find_by_pn(pn_value) - - if entry is not None: - continue - - new_part = types.Part() - new_part.referencesProp = xml.referencesProp - - out_parts.add_entry(new_part, True) - - print("Saving {} work parts".format(out_parts.size())) - save_db(out_path, out_parts) diff --git a/src/ee/part/pn_part_search_list.py b/src/ee/part/pn_part_search_list.py new file mode 100644 index 0000000..049d0b8 --- /dev/null +++ b/src/ee/part/pn_part_search_list.py @@ -0,0 +1,44 @@ +from pathlib import Path + +from ee.part import PartDb, load_db, save_db, Part, fact_keys +from ee.xml import types + +__all__ = ["pn_part_search_list"] + +ignored_part_classes = [ + "mechanical" +] + + +def pn_part_search_list(in_path: Path, out_path: Path, supplier: str): + in_parts = load_db(in_path) + out_parts = PartDb() + + # print("loaded {} existing parts".format(in_parts.size())) + + for xml in in_parts.iterparts(): + part = Part(xml) + pn_value = next((p.valueProp for p in part.get_mpns()), None) + + part_class = part.find_fact(fact_keys.part_class) + if part_class: + if part_class.valueProp in ignored_part_classes: + continue + + if pn_value is None: + refs = [ref.referenceProp for ref in part.get_schematic_references()] + print("Skipping part with no part number: schematic reference: {}".format(", ".join(refs))) + continue + + entry = out_parts.find_by_pn(pn_value) + + if entry is not None: + continue + + new_part = types.Part() + new_part.referencesProp = xml.referencesProp + + out_parts.add_entry(new_part, True) + + # print("Saving {} work parts".format(out_parts.size())) + save_db(out_path, out_parts) diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py index c53b5da..2c8a88a 100644 --- a/src/ee/tools/ninja.py +++ b/src/ee/tools/ninja.py @@ -2,7 +2,7 @@ import argparse import os.path import sys from pathlib import Path -from typing import List, Union, Optional +from typing import List, Union from jinja2 import Environment, PackageLoader, select_autoescape @@ -92,7 +92,7 @@ def generate(project: Project): # Local part databases first part_dbs.extend([parent_dir_filter(p) / noext_filter(p) for p in parts_yaml_files]) - part_dbs.extend([Path("ee") / d / "normalized" for d in distributors]) + part_dbs.extend([Path("ee") / d / "parts" for d in distributors]) with build_ninja.open("w") as f: env = _create_env() diff --git a/src/ee/tools/part_create_distributor_search_list.py b/src/ee/tools/part_create_distributor_search_list.py deleted file mode 100644 index 273b6d3..0000000 --- a/src/ee/tools/part_create_distributor_search_list.py +++ /dev/null @@ -1,19 +0,0 @@ -import argparse -from pathlib import Path - -from ee.part.create_distributor_search_list import create_distributor_search_list - -parser = argparse.ArgumentParser() - -parser.add_argument("--in", - dest="in_path", - required=True, - metavar="PART DB") - -parser.add_argument("--out", - required=True, - metavar="PART DB") - -args = parser.parse_args() - -create_distributor_search_list(Path(args.in_path), Path(args.out)) diff --git a/src/ee/tools/pn_part_search_list.py b/src/ee/tools/pn_part_search_list.py new file mode 100644 index 0000000..f82808c --- /dev/null +++ b/src/ee/tools/pn_part_search_list.py @@ -0,0 +1,23 @@ +import argparse +from pathlib import Path + +from ee.part.pn_part_search_list import pn_part_search_list + +parser = argparse.ArgumentParser() + +parser.add_argument("--in", + dest="in_path", + required=True, + metavar="PART DB") + +parser.add_argument("--out", + required=True, + metavar="PART DB") + +parser.add_argument("--supplier", + required=True, + metavar="SUPPLIER") + +args = parser.parse_args() + +pn_part_search_list(Path(args.in_path), Path(args.out), args.supplier) diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2 index 23bef37..ea979da 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -21,9 +21,9 @@ rule kicad-make-bom description = kicad-make-bom $out command = $ee kicad-make-bom --sch $sch --out $out $strategy -rule part-create-distributor-search-list - description = part-create-distributor-search-list distributor: $distributor - command = $ee part-create-distributor-search-list --in $in --out $out +rule pn-part-search-list + description = pn-part-search-list supplier: $supplier + command = $ee pn-part-search-list --in $in --out $out --supplier $supplier rule digikey-search-parts description = digikey-search-parts @@ -45,6 +45,10 @@ rule create-bom description = create-bom command = $ee create-bom --schematic $schematic --part-db $part_dbs --out $out $strategy +rule export-order + description = export-order + command = $ee export-order --order $order $part_dbs --out-dir $out_dir + rule import-parts-yaml description = import-parts-yaml $in command = $ee import-parts-yaml --in $in --out $out @@ -61,16 +65,16 @@ build ee/sch.xml: kicad-make-bom $sch strategy = --strategy {{ project.cfg["kicad-project"]["strategy"] }} {%- endif %} {%- endif %} -{% for d in distributors %} -# Distributor {{ d }} -build ee/{{ d }}/search-list.xml: part-create-distributor-search-list ee/sch.xml - distributor = {{ d }} +{% for s in distributors %} +# Supplier {{ s }} +build ee/{{ s }}/search-list.xml: pn-part-search-list ee/sch.xml + supplier = {{ s }} -build ee/{{ d }}/downloaded.xml: {{ d }}-search-parts ee/{{ d }}/search-list.xml +build ee/{{ s }}/downloaded.xml: {{ s }}-search-parts ee/{{ s }}/search-list.xml -build ee/{{ d }}/normalized.xml: {{ d }}-normalize-facts ee/{{ d }}/downloaded.xml +build ee/{{ s }}/parts.xml: {{ s }}-normalize-facts ee/{{ s }}/downloaded.xml -default ee/{{ d }}/normalized.xml +default ee/{{ s }}/parts.xml {%- endfor %} {%- for f in parts_yaml_files %} @@ -86,7 +90,12 @@ build ee/bom.xml | $report_dir/bom.rst: create-bom ee/sch.xml {%- for p in part_ strategy = --strategy {{ project.cfg["create-bom"]["strategy"] }} {%- endif %} -default ee/bom.xml +build ee/orders/index.xml: export-order ee/bom.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %} + order = ee/bom.xml + part_dbs ={%- for p in part_dbs %} --part-db {{ p }}.xml{% endfor %} + out_dir = ee/orders + +default ee/orders/index.xml rule seeed-download-opl description = seeed-download-opl $opl -- cgit v1.2.3