aboutsummaryrefslogtreecommitdiff
path: root/src/ee/project
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-03-28 16:38:50 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-03-28 16:43:14 +0100
commitfa85d46af0b91477cf354947df628af0dc0d2800 (patch)
treeb18b775d232560f57eaeb3f43d0861b98201d4ef /src/ee/project
parent52401b170d8f1c9deaa153acca76e7d6060a06df (diff)
downloadee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.gz
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.bz2
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.xz
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.zip
ee.xsd:
o Renaming <part-uri> to <part-reference>. o Adding <supplier> on <part>, removing from <supplier-part-number>. A part can have exactly one part. create-order: o Creating anonymous part objects, with two references, one schematic reference and one part-uri reference to the selected part. o Redoing how the order is calculated with the new ObjDb structure. ee.part.Part: o Absorbing bom_file_utils into Part. Much better wrapper object around the xml goop.
Diffstat (limited to 'src/ee/project')
-rw-r--r--src/ee/project/__init__.py17
-rw-r--r--src/ee/project/report.py16
2 files changed, 28 insertions, 5 deletions
diff --git a/src/ee/project/__init__.py b/src/ee/project/__init__.py
index 6851256..bca9984 100644
--- a/src/ee/project/__init__.py
+++ b/src/ee/project/__init__.py
@@ -1,7 +1,9 @@
import configparser
from pathlib import Path
+from ee import EeException
from ee.tools import mk_parents
+from ee.xml.uris import DIGIKEY_URI
def load_config(project_dir: Path) -> configparser.ConfigParser:
@@ -17,6 +19,12 @@ def load_config(project_dir: Path) -> configparser.ConfigParser:
return config
+class SupplierDescriptor(object):
+ def __init__(self, key: str, uri: str):
+ self.key = key
+ self.uri = uri
+
+
class Project(object):
def __init__(self, project_dir: Path, cfg: configparser.ConfigParser):
self.report_dir = project_dir / "ee" / "reports"
@@ -24,6 +32,15 @@ class Project(object):
self.project_dir = project_dir
self._cfg = cfg
+ # TODO: read from config
+ self._suppliers = [SupplierDescriptor("digikey", DIGIKEY_URI)]
+
+ def get_supplier_by_key(self, key) -> SupplierDescriptor:
+ sd = next((s for s in self._suppliers if s.key == key), None)
+ if sd:
+ return sd
+ raise EeException("No such supplier configured: {}".format(key))
+
@property
def cfg(self):
return self._cfg
diff --git a/src/ee/project/report.py b/src/ee/project/report.py
index 80e590a..26cdaa3 100644
--- a/src/ee/project/report.py
+++ b/src/ee/project/report.py
@@ -3,8 +3,9 @@ from typing import Optional
from jinja2 import Environment, PackageLoader, select_autoescape
+from ee.part import Part
from ee.tools import mk_parents
-from ee.xml import types, bom_file_utils
+from ee.xml import types
class Message(object):
@@ -29,12 +30,16 @@ def subsubsubsection_filter(s: str):
return "{}\n{}".format(s, "." * len(s))
-def first_pn_filter(part: types.Part):
- return next(iter(bom_file_utils.part_numbers(part)), None)
+def first_ref_filter(part: Part) -> Optional[types.SchematicReference]:
+ return part.get_only_schematic_reference()
-def first_spn_filter(part: types.Part):
- return next(iter(bom_file_utils.supplier_part_numbers(part)), None)
+def first_pn_filter(part: Part) -> Optional[types.PartNumber]:
+ return part.get_only_mpn()
+
+
+def first_spn_filter(part: Part) -> Optional[types.SupplierPartNumber]:
+ return part.get_only_spn()
def save_report(package: str, template_name: str, out_file: Path, **kwargs):
@@ -45,6 +50,7 @@ def save_report(package: str, template_name: str, out_file: Path, **kwargs):
env.filters["subsection"] = subsection_filter
env.filters["subsubsection"] = subsubsection_filter
env.filters["subsubsubsection"] = subsubsubsection_filter
+ env.filters["first_ref"] = first_ref_filter
env.filters["first_pn"] = first_pn_filter
env.filters["first_spn"] = first_spn_filter