aboutsummaryrefslogtreecommitdiff
path: root/src/ee/xml
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/xml')
-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
3 files changed, 69 insertions, 322 deletions
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)