aboutsummaryrefslogtreecommitdiff
path: root/src/ee/part
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/part')
-rw-r--r--src/ee/part/__init__.py24
-rw-r--r--src/ee/part/create_distributor_search_list.py10
2 files changed, 11 insertions, 23 deletions
diff --git a/src/ee/part/__init__.py b/src/ee/part/__init__.py
index 45561ec..36a3d3c 100644
--- a/src/ee/part/__init__.py
+++ b/src/ee/part/__init__.py
@@ -1,9 +1,7 @@
from pathlib import Path
from typing import List, MutableMapping, Optional, Iterator
-from ee import EeException
from ee.xml import types, bom_file_utils
-from ee.xml.bom_file_utils import find_pn, find_dpn, find_root_tag
__all__ = [
"PartDb",
@@ -17,10 +15,10 @@ class Entry(object):
self.new = new
self.part = part
- self.pn = find_pn(part)
+ self.pn = next((p.valueProp for p in bom_file_utils.part_numbers(part)), None)
def dpn(self, uri: str):
- return find_dpn(self.part, uri)
+ return [spn for spn in bom_file_utils.supplier_part_numbers(self.part) if spn.supplierProp == uri]
class PartDb(object):
@@ -42,7 +40,7 @@ class PartDb(object):
def iterparts(self, sort=False) -> Iterator[types.Part]:
it = (e.part for e in self.parts)
- return sorted(it, key=lambda p: p.idProp) if sort else it
+ return sorted(it, key=lambda p: p.uriProp) if sort else it
def size(self) -> int:
return len(self.parts)
@@ -51,16 +49,6 @@ class PartDb(object):
entry = self.pn_index.get(pn, None)
return entry.part if entry else None
- def find_by_dpn(self, distributor: str, pn: str) -> types.Part:
- idx = self.dpn_indexes.get(distributor)
-
- if idx is None:
- tmp = [(find_dpn(entry.part, distributor), entry) for entry in self.parts]
- idx = {dpn: entry for dpn, entry in tmp if dpn is not None}
- self.dpn_indexes[distributor] = idx
-
- return idx[pn].part
-
def load_db(path: Path) -> PartDb:
db = PartDb()
@@ -76,10 +64,10 @@ def load_db(path: Path) -> PartDb:
return db
-def save_db(path: Path, db: PartDb):
+def save_db(path: Path, db: PartDb, sort=False):
part_db = types.PartDb()
parts = part_db.parts = types.PartList()
- parts.partProp.extend(db.iterparts(sort=True))
+ parts.partProp.extend(db.iterparts(sort=sort))
with path.open("w") as f:
- part_db.export(outfile=f, level=0, name_=find_root_tag(part_db))
+ part_db.export(outfile=f, level=0, name_=bom_file_utils.find_root_tag(part_db))
diff --git a/src/ee/part/create_distributor_search_list.py b/src/ee/part/create_distributor_search_list.py
index 88e5a10..10160d4 100644
--- a/src/ee/part/create_distributor_search_list.py
+++ b/src/ee/part/create_distributor_search_list.py
@@ -1,8 +1,7 @@
from pathlib import Path
from ee.part import PartDb, load_db, save_db
-from ee.xml import types
-from ee.xml.bom_file_utils import *
+from ee.xml import types, bom_file_utils
__all__ = ["create_distributor_search_list"]
@@ -14,10 +13,11 @@ def create_distributor_search_list(in_path: Path, out_path: Path):
print("loaded {} existing parts".format(in_parts.size()))
for part in in_parts.iterparts():
- pn_value = find_pn(part)
+ pn_value = next((p.valueProp for p in bom_file_utils.part_numbers(part)), None)
if pn_value is None:
- print("Skipping part with no part number: id={}".format(part.idProp))
+ # TODO: use schematic reference if found
+ print("Skipping part with no part number: uri={}".format(part.uriProp))
continue
entry = out_parts.find_by_pn(pn_value)
@@ -26,7 +26,7 @@ def create_distributor_search_list(in_path: Path, out_path: Path):
continue
new_part = types.Part(id=pn_value)
- new_part.part_numbersProp = part.part_numbersProp
+ new_part.referencesProp = part.referencesProp
out_parts.add_entry(new_part, True)