diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-04-02 06:43:53 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-04-02 06:43:53 +0200 |
commit | e47a988e624e75ab3c0bac32041668647ab2a0f1 (patch) | |
tree | 7aa56c0e7ce934c9c5ee479fcb6252112f37f8db /src/ee | |
parent | c8c3c9e922915b7eddc05973f6f938c6a0cbedaf (diff) | |
download | ee-python-e47a988e624e75ab3c0bac32041668647ab2a0f1.tar.gz ee-python-e47a988e624e75ab3c0bac32041668647ab2a0f1.tar.bz2 ee-python-e47a988e624e75ab3c0bac32041668647ab2a0f1.tar.xz ee-python-e47a988e624e75ab3c0bac32041668647ab2a0f1.zip |
o Renaming create-order to create-bom.
Diffstat (limited to 'src/ee')
-rw-r--r-- | src/ee/bom/__init__.py (renamed from src/ee/order/__init__.py) | 56 | ||||
-rw-r--r-- | src/ee/bom/templates/bom.rst.j2 (renamed from src/ee/order/templates/order.rst.j2) | 14 | ||||
-rw-r--r-- | src/ee/project/__init__.py | 4 | ||||
-rw-r--r-- | src/ee/tools/create_bom.py (renamed from src/ee/tools/create_order.py) | 4 | ||||
-rw-r--r-- | src/ee/tools/init.py | 8 | ||||
-rw-r--r-- | src/ee/tools/templates/build.ninja.j2 | 20 |
6 files changed, 53 insertions, 53 deletions
diff --git a/src/ee/order/__init__.py b/src/ee/bom/__init__.py index 1624870..11c2fce 100644 --- a/src/ee/order/__init__.py +++ b/src/ee/bom/__init__.py @@ -9,10 +9,10 @@ from ee.part import PartDb, load_db, save_db, Part from ee.project import Project, report, SupplierDescriptor from ee.xml import types -__all__ = ["create_order"] +__all__ = ["create_bom"] -class OrderPart(object): +class BomPart(object): def __init__(self, part: types.Part): self.part = Part(part) ref = self.part.get_only_schematic_reference() @@ -21,20 +21,20 @@ class OrderPart(object): self.selected_part = None -def make_report(out_file, unresolved_parts, order_parts: ObjDb[OrderPart], supplier_parts: ObjDb[Path]): +def make_report(out_file, unresolved_parts, bom_parts: ObjDb[BomPart], supplier_parts: ObjDb[Path]): kwargs = { - "order_parts": order_parts, + "bom_parts": bom_parts, "supplier_parts": supplier_parts, "unresolved_parts": unresolved_parts, } - report.save_report("ee.order", "order.rst.j2", out_file, **kwargs) + report.save_report("ee.bom", "bom.rst.j2", out_file, **kwargs) def default_strategy(x): return x -def create_order(project: Project, schematic_path: Path, out_path: Path, part_dbs: List[Path], +def create_bom(project: Project, schematic_path: Path, out_path: Path, part_dbs: List[Path], fail_on_missing_parts: bool, strategy_name: Optional[str]): strategy = default_strategy if strategy_name: @@ -59,22 +59,22 @@ def create_order(project: Project, schematic_path: Path, out_path: Path, part_db supplier_parts.add(Part(xml)) sch_db = load_db(schematic_path) - order_parts: ObjDb[OrderPart] = ObjDb[OrderPart]() - order_parts.add_multi_index("supplier,pn", lambda op: [ + bom_parts: ObjDb[BomPart] = ObjDb[BomPart]() + bom_parts.add_multi_index("supplier,pn", lambda op: [ (op.part.supplierProp, ref.valueProp) for ref in op.part.get_mpns()] if op.part.supplier else None, multiple=True) for sch_part in sch_db.iterparts(): - part = OrderPart(sch_part) + part = BomPart(sch_part) part.part = strategy(part.part) if part.part is None: continue - order_parts.add(part) + bom_parts.add(part) - for order_part in order_parts: - sch_part_numbers = [pn.valueProp for pn in order_part.part.get_mpns()] - sch_supplier_part_numbers = [spn.valueProp for spn in order_part.part.get_spns()] + for bom_part in bom_parts: + sch_part_numbers = [pn.valueProp for pn in bom_part.part.get_mpns()] + sch_supplier_part_numbers = [spn.valueProp for spn in bom_part.part.get_spns()] for supplier in suppliers: pns = supplier_pn_idx.get(supplier.uri) @@ -82,41 +82,41 @@ def create_order(project: Project, schematic_path: Path, out_path: Path, part_db for sch_pn in sch_part_numbers: for supplier_part in pns.get(sch_pn, []): - order_part.available_from[supplier_part.uri] = supplier_part + bom_part.available_from[supplier_part.uri] = supplier_part for sch_spn in sch_supplier_part_numbers: for supplier_part in spns.get(sch_spn, []): - order_part.available_from[supplier_part.uri] = supplier_part + bom_part.available_from[supplier_part.uri] = supplier_part unresolved_parts = [] - for order_part in order_parts: - af = order_part.available_from + for bom_part in bom_parts: + af = bom_part.available_from if len(af) == 0: - unresolved_parts.append(order_part) + unresolved_parts.append(bom_part) elif len(af) == 1: - order_part.selected_part = next(iter(af.values())) + bom_part.selected_part = next(iter(af.values())) else: raise EeException("unimplemented: part ({}) available from multiple suppliers: {}". - format(order_part.ref, ",".join(af.keys()))) + format(bom_part.ref, ",".join(af.keys()))) - order_parts.add_index("uri", lambda op: op.selected_part.uri if op.selected_part else None) - order_parts.add_multi_index("supplier,part", lambda op: ( + bom_parts.add_index("uri", lambda op: op.selected_part.uri if op.selected_part else None) + bom_parts.add_multi_index("supplier,part", lambda op: ( op.selected_part.supplier, op.selected_part.uri) if op.selected_part else None) if len(unresolved_parts) and fail_on_missing_parts: - raise EeException("The order has parts that can't be found from any supplier") + raise EeException("The bom has parts that can't be found from any supplier") out_file = project.report_dir / (os.path.splitext(out_path.name)[0] + ".rst") - make_report(out_file, unresolved_parts, order_parts, supplier_parts) + make_report(out_file, unresolved_parts, bom_parts, supplier_parts) out_parts = PartDb() - for order_part in order_parts: - if not order_part.selected_part: + for bom_part in bom_parts: + if not bom_part.selected_part: continue - supplier_part = order_part.selected_part + supplier_part = bom_part.selected_part part = Part(types.Part(supplier=supplier_part.supplier)) - part.add_schematic_reference(order_part.part.get_exactly_one_schematic_reference().referenceProp) + part.add_schematic_reference(bom_part.part.get_exactly_one_schematic_reference().referenceProp) part.add_part_reference(supplier_part.uri) out_parts.add_entry(part, True) diff --git a/src/ee/order/templates/order.rst.j2 b/src/ee/bom/templates/bom.rst.j2 index b46600c..3463d90 100644 --- a/src/ee/order/templates/order.rst.j2 +++ b/src/ee/bom/templates/bom.rst.j2 @@ -1,6 +1,6 @@ -{% set order_part_uri_idx = order_parts.index("uri") -%} -Order -===== +{% set bom_part_uri_idx = bom_parts.index("uri") -%} +BOM +=== {% if unresolved_parts %} Unresolved parts: @@ -9,9 +9,9 @@ Unresolved parts: {%- endfor %} {%- endif %} -Parts for Order +Parts for BOM =============== -{% for op in order_parts %} +{% for op in bom_parts %} .. _ref-{{ op.ref }}: {{ op.ref | subsection }} @@ -49,7 +49,7 @@ MANY Part details ============ {%- set part_by_uri=supplier_parts.index("uri") %} -{% for supplier, partUris in order_parts.index("supplier,part").items() %} +{% for supplier, partUris in bom_parts.index("supplier,part").items() %} {{ ("From " + supplier) | subsection }} {% for partUri in partUris %} {%- set part=part_by_uri.get_single(partUri) %} @@ -66,7 +66,7 @@ Description {{ part.description }} {%- endif %} MPN {{ pn.value }} SPN {{ spn.value }} -Used by: {% for op in order_part_uri_idx.get(part.uriProp) %}`{{ op.ref }} <ref-{{ op.ref }}_>`_{{ ", " if not loop.last }}{% endfor %} +Used by: {% for op in bom_part_uri_idx.get(part.uriProp) %}`{{ op.ref }} <ref-{{ op.ref }}_>`_{{ ", " if not loop.last }}{% endfor %} =========== === {# Facts diff --git a/src/ee/project/__init__.py b/src/ee/project/__init__.py index 1adbbde..24635ee 100644 --- a/src/ee/project/__init__.py +++ b/src/ee/project/__init__.py @@ -54,7 +54,7 @@ class Project(object): return Project(project_dir, cfg) def save(self): - path = self.project_dir / ".ee" / "config" + path = self.project_dir / "eeconfig" mk_parents(path) - with (path).open("w") as f: + with path.open("w") as f: self._cfg.write(f) diff --git a/src/ee/tools/create_order.py b/src/ee/tools/create_bom.py index d740ff2..19521ce 100644 --- a/src/ee/tools/create_order.py +++ b/src/ee/tools/create_bom.py @@ -1,7 +1,7 @@ import argparse from pathlib import Path -from ee.order import create_order +from ee.bom import create_bom from ee.project import Project parser = argparse.ArgumentParser() @@ -28,4 +28,4 @@ project = Project.load() part_db_dirs = [Path(part_db) for part_db in args.part_db] fail_on_missing_parts = False -create_order(project, Path(args.schematic), Path(args.out), part_db_dirs, fail_on_missing_parts, args.strategy) +create_bom(project, Path(args.schematic), Path(args.out), part_db_dirs, fail_on_missing_parts, args.strategy) diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py index 74a67d1..c3d7e41 100644 --- a/src/ee/tools/init.py +++ b/src/ee/tools/init.py @@ -44,9 +44,9 @@ def init(project_dir: Path, basedir: Path, args): init_kicad_project(basedir, cfg, args) init_seeed_opl(project) - if args.create_order_strategy: - project.cfg.add_section("create-order") - project.cfg["create-order"]["strategy"] = args.create_order_strategy + if args.create_bom_strategy: + project.cfg.add_section("create-bom") + project.cfg["create-bom"]["strategy"] = args.create_bom_strategy print("Saving project. Now run 'ee ninja' to generate Ninja build file") project.save() @@ -61,7 +61,7 @@ parser.add_argument("--kicad-bom-strategy", required=False, metavar="PY CALLABLE") -parser.add_argument("--create-order-strategy", +parser.add_argument("--create-bom-strategy", required=False, metavar="PY CALLABLE") diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2 index 2a56bdc..23bef37 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -41,9 +41,9 @@ rule element14-normalize-facts description = element14-normalize-facts command = $ee element14-normalize-facts --in $in --out $out -rule create-order - description = create-order - command = $ee create-order --schematic $schematic --part-db $part_dbs --out $out $strategy +rule create-bom + description = create-bom + command = $ee create-bom --schematic $schematic --part-db $part_dbs --out $out $strategy rule import-parts-yaml description = import-parts-yaml $in @@ -79,21 +79,21 @@ build {{ out }}: import-parts-yaml {{ f }} # default {{ out }} {% endfor %} -build ee/order.xml | $report_dir/order.rst: create-order ee/sch.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %} +build ee/bom.xml | $report_dir/bom.rst: create-bom ee/sch.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %} schematic = ee/sch.xml part_dbs ={%- for p in part_dbs %} {{ p }}.xml{% endfor %} -{%- if project.cfg["create-order"] and project.cfg["create-order"]["strategy"] %} - strategy = --strategy {{ project.cfg["create-order"]["strategy"] }} +{%- if project.cfg["create-bom"] and project.cfg["create-bom"]["strategy"] %} + strategy = --strategy {{ project.cfg["create-bom"]["strategy"] }} {%- endif %} -default ee/order.xml +default ee/bom.xml rule seeed-download-opl description = seeed-download-opl $opl command = $ee seeed-download-opl --out $out --opl $opl -{%- if project.cfg.has_section("seeed-opl") -%} -{% set opls=project.cfg["seeed-opl"]["opls"].split(",") -%} +{% if project.cfg.has_section("seeed-opl") %} +{%- set opls=project.cfg["seeed-opl"]["opls"].split(",") -%} build seeed-download-opls: phony{%- for opl in opls %} ee/seeed/opl/{{ opl.strip() }}.xml{% endfor %} {%- for opl in opls %} {% set opl=opl.strip() -%} @@ -101,4 +101,4 @@ build seeed-download-opls: phony{%- for opl in opls %} ee/seeed/opl/{{ opl.strip build ee/seeed/opl/{{ opl }}.xml: seeed-download-opl opl = {{ opl }} {% endfor -%} -{% endif %} +{% endif -%} |