diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-02-24 21:51:38 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-02-24 21:51:38 +0100 |
commit | 80e0623913e87c6480049520590e424a831e0401 (patch) | |
tree | ff27e1d269cac886dd06ab4f9924719f84794e38 /src/ee/xml/bom_file_utils.py | |
parent | 8aae5d032dd30118b6d992018391a8bd5be759e4 (diff) | |
download | ee-python-80e0623913e87c6480049520590e424a831e0401.tar.gz ee-python-80e0623913e87c6480049520590e424a831e0401.tar.bz2 ee-python-80e0623913e87c6480049520590e424a831e0401.tar.xz ee-python-80e0623913e87c6480049520590e424a831e0401.zip |
Digikey: replacing requests-based code with selenium.
Adding new tools: digikey-import-parts and digikey-refresh-parts.
Diffstat (limited to 'src/ee/xml/bom_file_utils.py')
-rw-r--r-- | src/ee/xml/bom_file_utils.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/ee/xml/bom_file_utils.py b/src/ee/xml/bom_file_utils.py new file mode 100644 index 0000000..f09a3dd --- /dev/null +++ b/src/ee/xml/bom_file_utils.py @@ -0,0 +1,50 @@ +from typing import List, Optional + +from ee.xml import bomFile + +__all__ = [ + "part_numbers", + "find_pn", + "find_dpn", +] + + +def part_numbers(part: bomFile.Part) -> List[bomFile.PartNumber]: + pns = part.part_numbersProp # type: bomFile.PartNumberList + + if pns is None: + return [] + + return pns.part_numberProp + + +def find_pn(part: bomFile.Part) -> str: + for pn in part_numbers(part): + if pn.distributor is None: + return pn.value + + +def find_dpn(part: bomFile.Part, distributor: str) -> str: + for pn in part_numbers(part): + if pn.distributor == distributor: + return pn.value + + +def find_fact_set(part: bomFile.Part, uri: str, create=False) -> Optional[bomFile.FactSet]: + fact_set_list: bomFile.FactSetList = part.fact_setsProp + + if fact_set_list is None: + if not create: + return + + fact_set_list = part.fact_setsProp = bomFile.FactSetList() + + for fs in fact_set_list.fact_setProp: + fact_set: bomFile.FactSet = fs + + if fact_set.sourceProp == uri: + return fact_set + + fact_set = bomFile.FactSet(source=uri) + fact_set_list.add_fact_set(fact_set) + return fact_set |