diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-16 22:17:33 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-23 07:30:03 +0100 |
commit | 1fe278b37b4031a42f8e27ee4f3251b474efcb16 (patch) | |
tree | e89454d2f868b491ba27792cafb1db8266ff1bb0 /src/ee/order | |
parent | 8e642991d557bd902b749ddd84e41d65c48f79cf (diff) | |
download | ee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.tar.gz ee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.tar.bz2 ee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.tar.xz ee-python-1fe278b37b4031a42f8e27ee4f3251b474efcb16.zip |
Starting some code around creating reports.
Diffstat (limited to 'src/ee/order')
-rw-r--r-- | src/ee/order/__init__.py | 27 | ||||
-rw-r--r-- | src/ee/order/templates/order.rst.j2 | 9 |
2 files changed, 25 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) diff --git a/src/ee/order/templates/order.rst.j2 b/src/ee/order/templates/order.rst.j2 new file mode 100644 index 0000000..ea1dbdf --- /dev/null +++ b/src/ee/order/templates/order.rst.j2 @@ -0,0 +1,9 @@ +Messages +======== +{% for o, messages in messages_by_object %} +{{ o | subsection }} +{% for m in messages %} +* {{ m.text }} +{% endfor %} +{% endfor %} + |