From 80e0623913e87c6480049520590e424a831e0401 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 24 Feb 2019 21:51:38 +0100 Subject: Digikey: replacing requests-based code with selenium. Adding new tools: digikey-import-parts and digikey-refresh-parts. --- src/ee/xml/bomFile.py | 582 ++++++++++++++++++++++++++++++++++++++++++- src/ee/xml/bom_file_utils.py | 50 ++++ src/ee/xml/uris.py | 7 + 3 files changed, 637 insertions(+), 2 deletions(-) create mode 100644 src/ee/xml/bom_file_utils.py create mode 100644 src/ee/xml/uris.py (limited to 'src/ee/xml') diff --git a/src/ee/xml/bomFile.py b/src/ee/xml/bomFile.py index 4467cde..5a78173 100644 --- a/src/ee/xml/bomFile.py +++ b/src/ee/xml/bomFile.py @@ -804,16 +804,90 @@ 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' % (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, **kwargs_): + def __init__(self, id=None, schema_reference=None, part_type=None, part_numbers=None, distributor_info=None, fact_sets=None, **kwargs_): self.original_tagname_ = None self.parent_object_ = kwargs_.get('parent_object_') self.id = _cast(None, id) self.schema_reference = schema_reference self.part_type = part_type self.part_numbers = part_numbers + self.distributor_info = distributor_info + self.fact_sets = fact_sets def factory(*args_, **kwargs_): if CurrentSubclassModule_ is not None: subclass = getSubclassFromModule_( @@ -840,6 +914,16 @@ class Part(GeneratedsSuper): def set_part_numbers(self, part_numbers): self.part_numbers = part_numbers part_numbersProp = property(get_part_numbers, set_part_numbers) + def get_distributor_info(self): + return self.distributor_info + 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_id(self): return self.id def set_id(self, id): @@ -849,7 +933,9 @@ class Part(GeneratedsSuper): if ( self.schema_reference is not None or self.part_type is not None or - self.part_numbers is not None + self.part_numbers is not None or + self.distributor_info is not None or + self.fact_sets is not None ): return True else: @@ -892,6 +978,10 @@ class Part(GeneratedsSuper): outfile.write('<%spart-type>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.part_type), input_name='part-type')), namespaceprefix_ , eol_)) 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) def build(self, node): already_processed = set() self.buildAttributes(node, node.attrib, already_processed) @@ -918,6 +1008,30 @@ class Part(GeneratedsSuper): obj_.build(child_) 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 element') + self.distributor_info = obj_ + obj_.original_tagname_ = 'distributor-info' + elif nodeName_ == 'fact-sets': + obj_ = FactSetList.factory(parent_object_=self) + obj_.build(child_) + self.fact_sets = obj_ + obj_.original_tagname_ = 'fact-sets' # end class Part @@ -1191,6 +1305,464 @@ 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' % (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' % (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%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 + def __init__(self, key=None, label=None, value=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.key = key + self.label = label + self.value = value + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, Fact) + if subclass is not None: + return subclass(*args_, **kwargs_) + if Fact.subclass: + return Fact.subclass(*args_, **kwargs_) + else: + return Fact(*args_, **kwargs_) + factory = staticmethod(factory) + def get_key(self): + return self.key + def set_key(self, key): + self.key = key + keyProp = property(get_key, set_key) + def get_label(self): + return self.label + def set_label(self, label): + self.label = label + labelProp = property(get_label, set_label) + def get_value(self): + return self.value + def set_value(self, value): + self.value = value + valueProp = property(get_value, set_value) + def hasContent_(self): + if ( + self.key is not None or + self.label is not None or + self.value is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Fact', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Fact') + 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_='Fact') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Fact', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='Fact'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Fact', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.key is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%skey>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.key), input_name='key')), namespaceprefix_ , eol_)) + if self.label is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%slabel>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.label), input_name='label')), namespaceprefix_ , eol_)) + if self.value is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%svalue>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.value), input_name='value')), namespaceprefix_ , eol_)) + 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_ == 'key': + key_ = child_.text + key_ = self.gds_validate_string(key_, node, 'key') + self.key = key_ + elif nodeName_ == 'label': + label_ = child_.text + label_ = self.gds_validate_string(label_, node, 'label') + self.label = label_ + elif nodeName_ == 'value': + value_ = child_.text + value_ = self.gds_validate_string(value_, node, 'value') + self.value = value_ +# end class Fact + + +class FactList(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, fact=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + if fact is None: + self.fact = [] + else: + self.fact = fact + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, FactList) + if subclass is not None: + return subclass(*args_, **kwargs_) + if FactList.subclass: + return FactList.subclass(*args_, **kwargs_) + else: + return FactList(*args_, **kwargs_) + factory = staticmethod(factory) + def get_fact(self): + return self.fact + def set_fact(self, fact): + self.fact = fact + def add_fact(self, value): + self.fact.append(value) + def add_fact(self, value): + self.fact.append(value) + def insert_fact_at(self, index, value): + self.fact.insert(index, value) + def replace_fact_at(self, index, value): + self.fact[index] = value + factProp = property(get_fact, set_fact) + def hasContent_(self): + if ( + self.fact + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('FactList') + 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_='FactList') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FactList', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%s' % (namespaceprefix_, name_, eol_)) + else: + outfile.write('/>%s' % (eol_, )) + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='FactList'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FactList', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + for fact_ in self.fact: + fact_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='fact', 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': + obj_ = Fact.factory(parent_object_=self) + obj_.build(child_) + self.fact.append(obj_) + obj_.original_tagname_ = 'fact' +# end class FactList + + +class DigikeyDistributorInfo(DistributorInfo): + subclass = None + superclass = DistributorInfo + 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) + if subclass is not None: + return subclass(*args_, **kwargs_) + if DigikeyDistributorInfo.subclass: + return DigikeyDistributorInfo.subclass(*args_, **kwargs_) + else: + return DigikeyDistributorInfo(*args_, **kwargs_) + factory = staticmethod(factory) + def get_state(self): + return self.state + def set_state(self, state): + self.state = state + stateProp = property(get_state, set_state) + def hasContent_(self): + if ( + self.state is not None or + super(DigikeyDistributorInfo, self).hasContent_() + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='DigikeyDistributorInfo', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('DigikeyDistributorInfo') + 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_='DigikeyDistributorInfo') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='DigikeyDistributorInfo', pretty_print=pretty_print) + showIndent(outfile, level, pretty_print) + outfile.write('%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) + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.state is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%sstate>%s%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.state), input_name='state')), namespaceprefix_ , eol_)) + 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): + super(DigikeyDistributorInfo, self).buildAttributes(node, attrs, already_processed) + 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 + + GDSClassesMapping = { 'bom-file': BomFile, } @@ -1321,6 +1893,12 @@ 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 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 diff --git a/src/ee/xml/uris.py b/src/ee/xml/uris.py new file mode 100644 index 0000000..7bf0487 --- /dev/null +++ b/src/ee/xml/uris.py @@ -0,0 +1,7 @@ +CAPACITOR = "http://purl.org/ee/part-type#capacitor" +RESISTOR = "http://purl.org/ee/part-type#resistor" +DIODE = "http://purl.org/ee/part-type#diode" +INDUCTOR = "http://purl.org/ee/part-type#inductor" +CRYSTAL = "http://purl.org/ee/part-type#inductor" + +DIGIKEY_URI = "https://digikey.com" -- cgit v1.2.3