From b462f533cba12d58c4b265c0a658909b0752153e Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 28 Mar 2019 21:23:27 +0100 Subject: create-distributor-search-list: Ignore mechanical parts. create-order: Adding an option for a strategy to ignore/modify parts. ninja/init: Moving strategy from ninja to init so they're more persistent. --- src/ee/order/__init__.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'src/ee/order/__init__.py') diff --git a/src/ee/order/__init__.py b/src/ee/order/__init__.py index fc112d1..1624870 100644 --- a/src/ee/order/__init__.py +++ b/src/ee/order/__init__.py @@ -1,6 +1,7 @@ import os.path +import pydoc from pathlib import Path -from typing import List, MutableMapping +from typing import List, MutableMapping, Optional from ee import EeException from ee.db import ObjDb @@ -29,8 +30,18 @@ def make_report(out_file, unresolved_parts, order_parts: ObjDb[OrderPart], suppl report.save_report("ee.order", "order.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], - fail_on_missing_parts: bool): + fail_on_missing_parts: bool, strategy_name: Optional[str]): + strategy = default_strategy + if strategy_name: + strategy = pydoc.locate(strategy_name) + if not callable(strategy): + raise EeException("Not a callable: {}, is a {}".format(strategy_name, type(strategy))) + supplier_parts = ObjDb[Part]() supplier_parts.add_unique_index("uri", lambda p: p.uri) supplier_parts.add_index("spn", lambda p: [ref.valueProp for ref in p.get_spns()], @@ -54,7 +65,12 @@ def create_order(project: Project, schematic_path: Path, out_path: Path, part_db op.part.get_mpns()] if op.part.supplier else None, multiple=True) for sch_part in sch_db.iterparts(): - order_parts.add(OrderPart(sch_part)) + part = OrderPart(sch_part) + part.part = strategy(part.part) + if part.part is None: + continue + + order_parts.add(part) for order_part in order_parts: sch_part_numbers = [pn.valueProp for pn in order_part.part.get_mpns()] -- cgit v1.2.3