aboutsummaryrefslogtreecommitdiff
path: root/src/ee/order/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/order/__init__.py')
-rw-r--r--src/ee/order/__init__.py22
1 files changed, 19 insertions, 3 deletions
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()]