aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-02-26 23:14:22 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-02-26 23:14:22 +0100
commitf14a40a4f80275daceeb73f944e1aa1f84d16c79 (patch)
tree9ce3cd2b8702214bc94ae3f38b568bf8bdd5eaa0
parent97c8bb9db96e27051f8746865f657408263db0b8 (diff)
downloadee-python-f14a40a4f80275daceeb73f944e1aa1f84d16c79.tar.gz
ee-python-f14a40a4f80275daceeb73f944e1aa1f84d16c79.tar.bz2
ee-python-f14a40a4f80275daceeb73f944e1aa1f84d16c79.tar.xz
ee-python-f14a40a4f80275daceeb73f944e1aa1f84d16c79.zip
o Removing digikey specific DistributionInfo element. Can be generic.
-rw-r--r--src/ee/digikey/search_parts.py20
-rw-r--r--src/ee/xml/bomFile.py340
-rw-r--r--src/ee/xml/bom_file_utils.py24
-rw-r--r--src/ee/xml/uris.py27
-rw-r--r--xsd/ee-bom.xsd31
5 files changed, 82 insertions, 360 deletions
diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py
index 62bb4ee..cad611b 100644
--- a/src/ee/digikey/search_parts.py
+++ b/src/ee/digikey/search_parts.py
@@ -4,23 +4,21 @@ from typing import List
from ee.digikey import Digikey, DigikeyParser, DigikeyClient, SearchResponseTypes, DigikeyProduct
from ee.part import PartDb, load_db, save_db
from ee.xml import bomFile, bom_file_utils
-from ee.xml.bomFile import DigikeyDistributorInfo
-from ee.xml.uris import DIGIKEY_URI
+from ee.xml.uris import DIGIKEY_URI, make_digikey_fact_key
__all__ = ["search_parts"]
-def resolved(di: DigikeyDistributorInfo, part: bomFile.Part, p: DigikeyProduct):
+def resolved(di: bomFile.DistributorInfo, part: bomFile.Part, p: DigikeyProduct):
di.stateProp = "resolved"
- fact_set = bom_file_utils.find_fact_set(part, DIGIKEY_URI, create=True)
-
# Remove the old list
- fact_set.factsProp = bomFile.FactList()
- facts: List[bomFile.Fact] = fact_set.factsProp.factProp
+ part.factsProp = bomFile.FactList()
+ facts: List[bomFile.Fact] = part.factsProp.factProp
for a in p.attributes:
- facts.append(bomFile.Fact(key=a.attribute_type.id, label=a.attribute_type.label, value=a.value))
+ key = make_digikey_fact_key(a.attribute_type.id)
+ facts.append(bomFile.Fact(key=key, label=a.attribute_type.label, value=a.value))
def search_parts(in_dir: Path, out_dir: Path, cache_dir: Path, force_refresh: bool):
@@ -49,12 +47,10 @@ def search_parts(in_dir: Path, out_dir: Path, cache_dir: Path, force_refresh: bo
print("could not find pn or dpn: part.id={}".format(part.idProp))
continue
- di = part.distributor_infoProp # type: DigikeyDistributorInfo
+ di = part.distributor_infoProp # type: bomFile.DistributorInfo
if di is None:
- di = bomFile.DigikeyDistributorInfo()
- di.extensiontype_ = "DigikeyDistributorInfo"
- di.original_tagname_ = "distributor-info"
+ di = bomFile.DistributorInfo()
part.distributor_infoProp = di
if force_refresh or di.stateProp != "resolved":
diff --git a/src/ee/xml/bomFile.py b/src/ee/xml/bomFile.py
index 2e2b5a7..7c14679 100644
--- a/src/ee/xml/bomFile.py
+++ b/src/ee/xml/bomFile.py
@@ -804,82 +804,10 @@ class BomFile(GeneratedsSuper):
# end class BomFile
-class DistributorInfo(GeneratedsSuper):
- subclass = None
- superclass = None
- def __init__(self, extensiontype_=None, **kwargs_):
- self.original_tagname_ = None
- self.parent_object_ = kwargs_.get('parent_object_')
- self.extensiontype_ = extensiontype_
- def factory(*args_, **kwargs_):
- if CurrentSubclassModule_ is not None:
- subclass = getSubclassFromModule_(
- CurrentSubclassModule_, DistributorInfo)
- if subclass is not None:
- return subclass(*args_, **kwargs_)
- if DistributorInfo.subclass:
- return DistributorInfo.subclass(*args_, **kwargs_)
- else:
- return DistributorInfo(*args_, **kwargs_)
- factory = staticmethod(factory)
- def get_extensiontype_(self): return self.extensiontype_
- def set_extensiontype_(self, extensiontype_): self.extensiontype_ = extensiontype_
- def hasContent_(self):
- if (
-
- ):
- return True
- else:
- return False
- def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', pretty_print=True):
- imported_ns_def_ = GenerateDSNamespaceDefs_.get('DistributorInfo')
- if imported_ns_def_ is not None:
- namespacedef_ = imported_ns_def_
- if pretty_print:
- eol_ = '\n'
- else:
- eol_ = ''
- if self.original_tagname_ is not None:
- name_ = self.original_tagname_
- showIndent(outfile, level, pretty_print)
- outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
- already_processed = set()
- self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='DistributorInfo')
- if self.hasContent_():
- outfile.write('>%s' % (eol_, ))
- self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='DistributorInfo', pretty_print=pretty_print)
- outfile.write('</%s%s>%s' % (namespaceprefix_, name_, eol_))
- else:
- outfile.write('/>%s' % (eol_, ))
- def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='DistributorInfo'):
- if self.extensiontype_ is not None and 'xsi:type' not in already_processed:
- already_processed.add('xsi:type')
- outfile.write(' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"')
- outfile.write(' xsi:type="%s"' % self.extensiontype_)
- pass
- def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', fromsubclass_=False, pretty_print=True):
- pass
- def build(self, node):
- already_processed = set()
- self.buildAttributes(node, node.attrib, already_processed)
- for child in node:
- nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
- self.buildChildren(child, node, nodeName_)
- return self
- def buildAttributes(self, node, attrs, already_processed):
- value = find_attr_value_('xsi:type', node)
- if value is not None and 'xsi:type' not in already_processed:
- already_processed.add('xsi:type')
- self.extensiontype_ = value
- def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
- pass
-# end class DistributorInfo
-
-
class Part(GeneratedsSuper):
subclass = None
superclass = None
- def __init__(self, id=None, schema_reference=None, part_type=None, part_numbers=None, distributor_info=None, fact_sets=None, **kwargs_):
+ def __init__(self, id=None, schema_reference=None, part_type=None, part_numbers=None, distributor_info=None, facts=None, **kwargs_):
self.original_tagname_ = None
self.parent_object_ = kwargs_.get('parent_object_')
self.id = _cast(None, id)
@@ -887,7 +815,7 @@ class Part(GeneratedsSuper):
self.part_type = part_type
self.part_numbers = part_numbers
self.distributor_info = distributor_info
- self.fact_sets = fact_sets
+ self.facts = facts
def factory(*args_, **kwargs_):
if CurrentSubclassModule_ is not None:
subclass = getSubclassFromModule_(
@@ -919,11 +847,11 @@ class Part(GeneratedsSuper):
def set_distributor_info(self, distributor_info):
self.distributor_info = distributor_info
distributor_infoProp = property(get_distributor_info, set_distributor_info)
- def get_fact_sets(self):
- return self.fact_sets
- def set_fact_sets(self, fact_sets):
- self.fact_sets = fact_sets
- fact_setsProp = property(get_fact_sets, set_fact_sets)
+ def get_facts(self):
+ return self.facts
+ def set_facts(self, facts):
+ self.facts = facts
+ factsProp = property(get_facts, set_facts)
def get_id(self):
return self.id
def set_id(self, id):
@@ -935,7 +863,7 @@ class Part(GeneratedsSuper):
self.part_type is not None or
self.part_numbers is not None or
self.distributor_info is not None or
- self.fact_sets is not None
+ self.facts is not None
):
return True
else:
@@ -979,9 +907,9 @@ class Part(GeneratedsSuper):
if self.part_numbers is not None:
self.part_numbers.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-numbers', pretty_print=pretty_print)
if self.distributor_info is not None:
- self.distributor_info.export(outfile, level, namespaceprefix_, namespacedef_='', pretty_print=pretty_print)
- if self.fact_sets is not None:
- self.fact_sets.export(outfile, level, namespaceprefix_, namespacedef_='', name_='fact-sets', pretty_print=pretty_print)
+ self.distributor_info.export(outfile, level, namespaceprefix_, namespacedef_='', name_='distributor-info', pretty_print=pretty_print)
+ if self.facts is not None:
+ self.facts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='facts', pretty_print=pretty_print)
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
@@ -1009,29 +937,15 @@ class Part(GeneratedsSuper):
self.part_numbers = obj_
obj_.original_tagname_ = 'part-numbers'
elif nodeName_ == 'distributor-info':
- type_name_ = child_.attrib.get(
- '{http://www.w3.org/2001/XMLSchema-instance}type')
- if type_name_ is None:
- type_name_ = child_.attrib.get('type')
- if type_name_ is not None:
- type_names_ = type_name_.split(':')
- if len(type_names_) == 1:
- type_name_ = type_names_[0]
- else:
- type_name_ = type_names_[1]
- class_ = globals()[type_name_]
- obj_ = class_.factory()
- obj_.build(child_)
- else:
- raise NotImplementedError(
- 'Class not implemented for <distributor_info> element')
+ obj_ = DistributorInfo.factory(parent_object_=self)
+ obj_.build(child_)
self.distributor_info = obj_
obj_.original_tagname_ = 'distributor-info'
- elif nodeName_ == 'fact-sets':
- obj_ = FactSetList.factory(parent_object_=self)
+ elif nodeName_ == 'facts':
+ obj_ = FactList.factory(parent_object_=self)
obj_.build(child_)
- self.fact_sets = obj_
- obj_.original_tagname_ = 'fact-sets'
+ self.facts = obj_
+ obj_.original_tagname_ = 'facts'
# end class Part
@@ -1305,187 +1219,6 @@ class PartNumberList(GeneratedsSuper):
# end class PartNumberList
-class FactSetList(GeneratedsSuper):
- subclass = None
- superclass = None
- def __init__(self, fact_set=None, **kwargs_):
- self.original_tagname_ = None
- self.parent_object_ = kwargs_.get('parent_object_')
- if fact_set is None:
- self.fact_set = []
- else:
- self.fact_set = fact_set
- def factory(*args_, **kwargs_):
- if CurrentSubclassModule_ is not None:
- subclass = getSubclassFromModule_(
- CurrentSubclassModule_, FactSetList)
- if subclass is not None:
- return subclass(*args_, **kwargs_)
- if FactSetList.subclass:
- return FactSetList.subclass(*args_, **kwargs_)
- else:
- return FactSetList(*args_, **kwargs_)
- factory = staticmethod(factory)
- def get_fact_set(self):
- return self.fact_set
- def set_fact_set(self, fact_set):
- self.fact_set = fact_set
- def add_fact_set(self, value):
- self.fact_set.append(value)
- def add_fact_set(self, value):
- self.fact_set.append(value)
- def insert_fact_set_at(self, index, value):
- self.fact_set.insert(index, value)
- def replace_fact_set_at(self, index, value):
- self.fact_set[index] = value
- fact_setProp = property(get_fact_set, set_fact_set)
- def hasContent_(self):
- if (
- self.fact_set
- ):
- return True
- else:
- return False
- def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactSetList', pretty_print=True):
- imported_ns_def_ = GenerateDSNamespaceDefs_.get('FactSetList')
- if imported_ns_def_ is not None:
- namespacedef_ = imported_ns_def_
- if pretty_print:
- eol_ = '\n'
- else:
- eol_ = ''
- if self.original_tagname_ is not None:
- name_ = self.original_tagname_
- showIndent(outfile, level, pretty_print)
- outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
- already_processed = set()
- self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='FactSetList')
- if self.hasContent_():
- outfile.write('>%s' % (eol_, ))
- self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FactSetList', pretty_print=pretty_print)
- showIndent(outfile, level, pretty_print)
- outfile.write('</%s%s>%s' % (namespaceprefix_, name_, eol_))
- else:
- outfile.write('/>%s' % (eol_, ))
- def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='FactSetList'):
- pass
- def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactSetList', fromsubclass_=False, pretty_print=True):
- if pretty_print:
- eol_ = '\n'
- else:
- eol_ = ''
- for fact_set_ in self.fact_set:
- fact_set_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='fact-set', pretty_print=pretty_print)
- def build(self, node):
- already_processed = set()
- self.buildAttributes(node, node.attrib, already_processed)
- for child in node:
- nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
- self.buildChildren(child, node, nodeName_)
- return self
- def buildAttributes(self, node, attrs, already_processed):
- pass
- def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
- if nodeName_ == 'fact-set':
- obj_ = FactSet.factory(parent_object_=self)
- obj_.build(child_)
- self.fact_set.append(obj_)
- obj_.original_tagname_ = 'fact-set'
-# end class FactSetList
-
-
-class FactSet(GeneratedsSuper):
- subclass = None
- superclass = None
- def __init__(self, source=None, facts=None, **kwargs_):
- self.original_tagname_ = None
- self.parent_object_ = kwargs_.get('parent_object_')
- self.source = source
- self.facts = facts
- def factory(*args_, **kwargs_):
- if CurrentSubclassModule_ is not None:
- subclass = getSubclassFromModule_(
- CurrentSubclassModule_, FactSet)
- if subclass is not None:
- return subclass(*args_, **kwargs_)
- if FactSet.subclass:
- return FactSet.subclass(*args_, **kwargs_)
- else:
- return FactSet(*args_, **kwargs_)
- factory = staticmethod(factory)
- def get_source(self):
- return self.source
- def set_source(self, source):
- self.source = source
- sourceProp = property(get_source, set_source)
- def get_facts(self):
- return self.facts
- def set_facts(self, facts):
- self.facts = facts
- factsProp = property(get_facts, set_facts)
- def hasContent_(self):
- if (
- self.source is not None or
- self.facts is not None
- ):
- return True
- else:
- return False
- def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactSet', pretty_print=True):
- imported_ns_def_ = GenerateDSNamespaceDefs_.get('FactSet')
- if imported_ns_def_ is not None:
- namespacedef_ = imported_ns_def_
- if pretty_print:
- eol_ = '\n'
- else:
- eol_ = ''
- if self.original_tagname_ is not None:
- name_ = self.original_tagname_
- showIndent(outfile, level, pretty_print)
- outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
- already_processed = set()
- self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='FactSet')
- if self.hasContent_():
- outfile.write('>%s' % (eol_, ))
- self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FactSet', pretty_print=pretty_print)
- showIndent(outfile, level, pretty_print)
- outfile.write('</%s%s>%s' % (namespaceprefix_, name_, eol_))
- else:
- outfile.write('/>%s' % (eol_, ))
- def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='FactSet'):
- pass
- def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactSet', fromsubclass_=False, pretty_print=True):
- if pretty_print:
- eol_ = '\n'
- else:
- eol_ = ''
- if self.source is not None:
- showIndent(outfile, level, pretty_print)
- outfile.write('<%ssource>%s</%ssource>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.source), input_name='source')), namespaceprefix_ , eol_))
- if self.facts is not None:
- self.facts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='facts', pretty_print=pretty_print)
- def build(self, node):
- already_processed = set()
- self.buildAttributes(node, node.attrib, already_processed)
- for child in node:
- nodeName_ = Tag_pattern_.match(child.tag).groups()[-1]
- self.buildChildren(child, node, nodeName_)
- return self
- def buildAttributes(self, node, attrs, already_processed):
- pass
- def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
- if nodeName_ == 'source':
- source_ = child_.text
- source_ = self.gds_validate_string(source_, node, 'source')
- self.source = source_
- elif nodeName_ == 'facts':
- obj_ = FactList.factory(parent_object_=self)
- obj_.build(child_)
- self.facts = obj_
- obj_.original_tagname_ = 'facts'
-# end class FactSet
-
-
class Fact(GeneratedsSuper):
subclass = None
superclass = None
@@ -1681,24 +1414,23 @@ class FactList(GeneratedsSuper):
# end class FactList
-class DigikeyDistributorInfo(DistributorInfo):
+class DistributorInfo(GeneratedsSuper):
subclass = None
- superclass = DistributorInfo
+ superclass = None
def __init__(self, state=None, **kwargs_):
self.original_tagname_ = None
self.parent_object_ = kwargs_.get('parent_object_')
- super(DigikeyDistributorInfo, self).__init__( **kwargs_)
self.state = state
def factory(*args_, **kwargs_):
if CurrentSubclassModule_ is not None:
subclass = getSubclassFromModule_(
- CurrentSubclassModule_, DigikeyDistributorInfo)
+ CurrentSubclassModule_, DistributorInfo)
if subclass is not None:
return subclass(*args_, **kwargs_)
- if DigikeyDistributorInfo.subclass:
- return DigikeyDistributorInfo.subclass(*args_, **kwargs_)
+ if DistributorInfo.subclass:
+ return DistributorInfo.subclass(*args_, **kwargs_)
else:
- return DigikeyDistributorInfo(*args_, **kwargs_)
+ return DistributorInfo(*args_, **kwargs_)
factory = staticmethod(factory)
def get_state(self):
return self.state
@@ -1707,14 +1439,13 @@ class DigikeyDistributorInfo(DistributorInfo):
stateProp = property(get_state, set_state)
def hasContent_(self):
if (
- self.state is not None or
- super(DigikeyDistributorInfo, self).hasContent_()
+ self.state is not None
):
return True
else:
return False
- def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DigikeyDistributorInfo', pretty_print=True):
- imported_ns_def_ = GenerateDSNamespaceDefs_.get('DigikeyDistributorInfo')
+ def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', pretty_print=True):
+ imported_ns_def_ = GenerateDSNamespaceDefs_.get('DistributorInfo')
if imported_ns_def_ is not None:
namespacedef_ = imported_ns_def_
if pretty_print:
@@ -1726,18 +1457,17 @@ class DigikeyDistributorInfo(DistributorInfo):
showIndent(outfile, level, pretty_print)
outfile.write('<%s%s%s' % (namespaceprefix_, name_, namespacedef_ and ' ' + namespacedef_ or '', ))
already_processed = set()
- self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='DigikeyDistributorInfo')
+ self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='DistributorInfo')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
- self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='DigikeyDistributorInfo', pretty_print=pretty_print)
+ self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='DistributorInfo', pretty_print=pretty_print)
showIndent(outfile, level, pretty_print)
outfile.write('</%s%s>%s' % (namespaceprefix_, name_, eol_))
else:
outfile.write('/>%s' % (eol_, ))
- def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='DigikeyDistributorInfo'):
- super(DigikeyDistributorInfo, self).exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='DigikeyDistributorInfo')
- def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DigikeyDistributorInfo', fromsubclass_=False, pretty_print=True):
- super(DigikeyDistributorInfo, self).exportChildren(outfile, level, namespaceprefix_, name_, True, pretty_print=pretty_print)
+ def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='DistributorInfo'):
+ pass
+ def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DistributorInfo', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
@@ -1753,14 +1483,13 @@ class DigikeyDistributorInfo(DistributorInfo):
self.buildChildren(child, node, nodeName_)
return self
def buildAttributes(self, node, attrs, already_processed):
- super(DigikeyDistributorInfo, self).buildAttributes(node, attrs, already_processed)
+ pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'state':
state_ = child_.text
state_ = self.gds_validate_string(state_, node, 'state')
self.state = state_
- super(DigikeyDistributorInfo, self).buildChildren(child_, node, nodeName_, True)
-# end class DigikeyDistributorInfo
+# end class DistributorInfo
GDSClassesMapping = {
@@ -1894,12 +1623,9 @@ if __name__ == '__main__':
__all__ = [
"BomFile",
- "DigikeyDistributorInfo",
"DistributorInfo",
"Fact",
"FactList",
- "FactSet",
- "FactSetList",
"Part",
"PartList",
"PartNumber",
diff --git a/src/ee/xml/bom_file_utils.py b/src/ee/xml/bom_file_utils.py
index 15f99b2..8ef76e0 100644
--- a/src/ee/xml/bom_file_utils.py
+++ b/src/ee/xml/bom_file_utils.py
@@ -39,21 +39,15 @@ def find_dpn(part: bomFile.Part, distributor: str) -> str:
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
+def facts(part: bomFile.Part, create=False) -> Optional[bomFile.FactList]:
+ fs: bomFile.FactList = part.factsProp
- if fact_set_list is None:
- if not create:
- return
+ if fs is not None:
+ return fs
- fact_set_list = part.fact_setsProp = bomFile.FactSetList()
+ if not create:
+ return
- 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
+ fs = bomFile.FactList()
+ part.factsProp = fs
+ return fs
diff --git a/src/ee/xml/uris.py b/src/ee/xml/uris.py
index 7bf0487..f0a1022 100644
--- a/src/ee/xml/uris.py
+++ b/src/ee/xml/uris.py
@@ -1,3 +1,5 @@
+from typing import Optional
+
CAPACITOR = "http://purl.org/ee/part-type#capacitor"
RESISTOR = "http://purl.org/ee/part-type#resistor"
DIODE = "http://purl.org/ee/part-type#diode"
@@ -5,3 +7,28 @@ INDUCTOR = "http://purl.org/ee/part-type#inductor"
CRYSTAL = "http://purl.org/ee/part-type#inductor"
DIGIKEY_URI = "https://digikey.com"
+
+_DIGIKEY_FACT_KEY_PREFIX = "http://purl.org/trygvis/ee/digikey-fact-key#"
+
+
+def make_digikey_fact_key(key: int) -> str:
+ return _DIGIKEY_FACT_KEY_PREFIX + str(key)
+
+
+def is_digikey_fact_key(uri: str) -> bool:
+ return uri.startswith(_DIGIKEY_FACT_KEY_PREFIX)
+
+
+def parse_digikey_fact_key(uri: str) -> Optional[int]:
+ if uri.startswith(_DIGIKEY_FACT_KEY_PREFIX):
+ try:
+ return int(uri[len(_DIGIKEY_FACT_KEY_PREFIX):])
+ except ValueError:
+ pass
+
+
+_FACT_KEY_PREFIX = "http://purl.org/trygvis/ee/fact-key#"
+
+
+def make_fact_key(name: str) -> str:
+ return "{}{}".format(_FACT_KEY_PREFIX, name)
diff --git a/xsd/ee-bom.xsd b/xsd/ee-bom.xsd
index a357deb..e0c523e 100644
--- a/xsd/ee-bom.xsd
+++ b/xsd/ee-bom.xsd
@@ -14,15 +14,13 @@
</xs:sequence>
</xs:complexType>
- <xs:complexType name="DistributorInfo" abstract="true"/>
-
<xs:complexType name="Part">
<xs:sequence>
<xs:element name="schema-reference" type="xs:string"/>
<xs:element name="part-type" type="xs:anyURI"/>
<xs:element name="part-numbers" type="PartNumberList"/>
<xs:element name="distributor-info" type="DistributorInfo"/>
- <xs:element name="fact-sets" type="FactSetList"/>
+ <xs:element name="facts" type="FactList"/>
</xs:sequence>
<xs:attribute ref="id" use="required"/>
</xs:complexType>
@@ -46,19 +44,6 @@
</xs:sequence>
</xs:complexType>
- <xs:complexType name="FactSetList">
- <xs:sequence>
- <xs:element name="fact-set" type="FactSet" maxOccurs="unbounded"/>
- </xs:sequence>
- </xs:complexType>
-
- <xs:complexType name="FactSet">
- <xs:sequence>
- <xs:element name="source" type="xs:anyURI"/>
- <xs:element name="facts" type="FactList"/>
- </xs:sequence>
- </xs:complexType>
-
<xs:complexType name="Fact">
<xs:sequence>
<xs:element name="key" type="xs:anyURI"/>
@@ -73,16 +58,10 @@
</xs:sequence>
</xs:complexType>
- <!-- Digi-Key -->
-
- <xs:complexType name="DigikeyDistributorInfo">
- <xs:complexContent>
- <xs:extension base="DistributorInfo">
- <xs:sequence>
- <xs:element name="state" type="xs:string"/>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
+ <xs:complexType name="DistributorInfo">
+ <xs:sequence>
+ <xs:element name="state" type="xs:string"/>
+ </xs:sequence>
</xs:complexType>
</xs:schema>