aboutsummaryrefslogtreecommitdiff
path: root/src/ee/order
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/order')
-rw-r--r--src/ee/order/__init__.py124
-rw-r--r--src/ee/order/templates/order.rst.j289
2 files changed, 0 insertions, 213 deletions
diff --git a/src/ee/order/__init__.py b/src/ee/order/__init__.py
deleted file mode 100644
index 1624870..0000000
--- a/src/ee/order/__init__.py
+++ /dev/null
@@ -1,124 +0,0 @@
-import os.path
-import pydoc
-from pathlib import Path
-from typing import List, MutableMapping, Optional
-
-from ee import EeException
-from ee.db import ObjDb
-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"]
-
-
-class OrderPart(object):
- def __init__(self, part: types.Part):
- self.part = Part(part)
- ref = self.part.get_only_schematic_reference()
- self.ref = ref.referenceProp if ref else None
- self.available_from: MutableMapping[str, Part] = {}
- self.selected_part = None
-
-
-def make_report(out_file, unresolved_parts, order_parts: ObjDb[OrderPart], supplier_parts: ObjDb[Path]):
- kwargs = {
- "order_parts": order_parts,
- "supplier_parts": supplier_parts,
- "unresolved_parts": unresolved_parts,
- }
- 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, 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()],
- multiple=True)
- supplier_pn_idx = supplier_parts.add_multi_index("supplier,pn", lambda p: [
- (p.supplier, ref.valueProp) for ref in p.get_mpns()], multiple=True)
- supplier_spn_idx = supplier_parts.add_multi_index("supplier,spn", lambda p: [
- (p.supplier, ref.valueProp) for ref in p.get_spns()], multiple=True)
-
- suppliers: List[SupplierDescriptor] = [project.get_supplier_by_key(path.parent.name) for path in part_dbs]
- for path in part_dbs:
- for xml in load_db(path).iterparts():
- if not xml.supplierProp:
- continue
- 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: [
- (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.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()]
- sch_supplier_part_numbers = [spn.valueProp for spn in order_part.part.get_spns()]
-
- for supplier in suppliers:
- pns = supplier_pn_idx.get(supplier.uri)
- spns = supplier_spn_idx.get(supplier.uri)
-
- for sch_pn in sch_part_numbers:
- for supplier_part in pns.get(sch_pn, []):
- order_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
-
- unresolved_parts = []
- for order_part in order_parts:
- af = order_part.available_from
- if len(af) == 0:
- unresolved_parts.append(order_part)
- elif len(af) == 1:
- order_part.selected_part = next(iter(af.values()))
- else:
- raise EeException("unimplemented: part ({}) available from multiple suppliers: {}".
- format(order_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: (
- 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")
-
- out_file = project.report_dir / (os.path.splitext(out_path.name)[0] + ".rst")
- make_report(out_file, unresolved_parts, order_parts, supplier_parts)
-
- out_parts = PartDb()
- for order_part in order_parts:
- if not order_part.selected_part:
- continue
-
- supplier_part = order_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_part_reference(supplier_part.uri)
-
- out_parts.add_entry(part, True)
-
- save_db(out_path, out_parts)
diff --git a/src/ee/order/templates/order.rst.j2 b/src/ee/order/templates/order.rst.j2
deleted file mode 100644
index b46600c..0000000
--- a/src/ee/order/templates/order.rst.j2
+++ /dev/null
@@ -1,89 +0,0 @@
-{% set order_part_uri_idx = order_parts.index("uri") -%}
-Order
-=====
-
-{% if unresolved_parts %}
-Unresolved parts:
-{% for op in unresolved_parts %}
-* `{{ op.ref }} <ref-{{ op.ref }}_>`_
-{%- endfor %}
-{%- endif %}
-
-Parts for Order
-===============
-{% for op in order_parts %}
-.. _ref-{{ op.ref }}:
-
-{{ op.ref | subsection }}
-{% if op.available_from|length == 0 %}
-Could not find part.
-
-{% if op.part.get_mpns()|length == 1 -%}
-MPN: {{ op.part.get_mpns()[0].valueProp }}
-{% elif op.part.get_mpns()|length > 1 -%}
-{%- for mpn in op.part.get_mpns() %}
-MPNs:
-* {{ mpn.valueProp }}
-{%- endfor %}
-{%- endif -%}
-{% if op.part.get_spns()|length == 1 -%}
-SPN: {{ op.part.get_spns()[0].valueProp }}
-{% elif op.part.get_spns()|length > 1 -%}
-{%- for spn in op.part.get_spns() %}
-SPNs:
-* {{ spn.valueProp }}
-{%- endfor %}
-{%- endif -%}
-
-{% elif op.available_from|length == 1 %}
-{%- set part=op.available_from.values()|first %}
-{%- set pn=part|first_pn %}
-{%- set spn=part|first_spn %}
-Selected supplier: {{ part.supplier }}{{ (", pn: " + pn.valueProp) if pn else "" }}{{ (", spn: " + spn.valueProp) if spn else "" }}.
-Part: `{{pn.valueProp}} <part-{{pn.valueProp}}_>`_
-{% else %}
-MANY
-{% endif %}
-{%- endfor %}
-
-Part details
-============
-{%- set part_by_uri=supplier_parts.index("uri") %}
-{% for supplier, partUris in order_parts.index("supplier,part").items() %}
-{{ ("From " + supplier) | subsection }}
-{% for partUri in partUris %}
-{%- set part=part_by_uri.get_single(partUri) %}
-{%- set pn=part|first_pn %}
-{%- set spn=part|first_spn %}
-{%- set title=pn.valueProp if pn else (spn.valueProp if spn else "???") %}
-.. _part-{{title}}:
-
-{{ title|subsubsection }}
-
-=========== ===
-{%- if part.description %}
-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 %}
-=========== ===
-{#
-Facts
-.....
-
-{% for f in part.facts.fact %}
-f={{f}}
-{% endfor %}
-
-#}
-Documentation
-.............
-
-{% for l in part.get_links() %}
-{%- if l.relationProp == "http://purl.org/ee/link-relation#documentation" %}
-* `{{ l.title }} <{{ l.url }}>`__
-{%- endif %}
-{%- endfor %}
-{% endfor %}
-{% endfor %}