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__.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/ee/order/__init__.py b/src/ee/order/__init__.py
index 56d233f..1652f24 100644
--- a/src/ee/order/__init__.py
+++ b/src/ee/order/__init__.py
@@ -1,9 +1,11 @@
from functools import total_ordering
+from itertools import groupby
from pathlib import Path
from typing import List, Tuple
from ee import EeException
from ee.part import PartDb, load_db, save_db
+from ee.project import Project, report
from ee.xml import types, bom_file_utils
__all__ = ["create_order"]
@@ -26,7 +28,10 @@ class PartInfo(object):
return self.ref == other.ref
-def create_order(schematic_path: Path, out_path: Path, part_db_dirs: List[Path], fail_on_missing_parts: bool):
+def create_order(project: Project, schematic_path: Path, out_path: Path, part_db_dirs: List[Path],
+ fail_on_missing_parts: bool):
+ messages = []
+
sch_db = load_db(schematic_path)
dbs = [(path.parent.name, load_db(path)) for path in part_db_dirs]
@@ -36,8 +41,6 @@ def create_order(schematic_path: Path, out_path: Path, part_db_dirs: List[Path],
infos = [PartInfo(sch) for sch in sch_db.iterparts()]
for info in infos:
- print("Resolving {}".format(info.ref))
-
sch_part_numbers = info.part.referencesProp.part_number
sch_supplier_part_numbers: List[types.SupplierPartNumber] = info.part.referencesProp.supplier_part_number
@@ -70,18 +73,18 @@ def create_order(schematic_path: Path, out_path: Path, part_db_dirs: List[Path],
break
for info in infos:
- print("Resolved {} to {}".format(info.ref, info.available_from))
+ if len(info.available_from):
+ strings = ["{} from {}".format(part.uri, s) for s, part in info.available_from]
+ text = "Resolved {} to {}".format(info.ref, ", ".join(strings))
+ messages.append(report.Message(object=info.ref, text=text))
- warnings = []
has_missing_parts = False
for info in infos:
if len(info.available_from) == 0:
has_missing_parts = True
- warnings.append("Could not find {} in any database, part numbers: {}".
- format(info.ref, ", ".join([p.value for p in bom_file_utils.part_numbers(info.part)])))
-
- for w in sorted(warnings):
- print(w)
+ text = "Could not find {} in any database, part numbers: {}". \
+ format(info.ref, ", ".join([p.value for p in bom_file_utils.part_numbers(info.part)]))
+ messages.append(report.Message(object=info.ref, text=text))
if has_missing_parts and fail_on_missing_parts:
raise EeException("The order has parts that can't be found from any supplier")
@@ -97,5 +100,7 @@ def create_order(schematic_path: Path, out_path: Path, part_db_dirs: List[Path],
out_parts.add_entry(part, True)
- print("Saving {} work parts".format(out_parts.size()))
save_db(out_path, out_parts)
+ # messages
+ kwargs = {"messages_by_object": groupby(messages, lambda m: m.object)}
+ report.save_report("ee.order", "order.rst.j2", project.report_dir / "order.rst", **kwargs)