diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-11 14:48:15 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-11 14:48:15 +0200 |
commit | 0149fcfa2bd9ac8c9f6b05851f7264f005aa2305 (patch) | |
tree | 3757a7148377bf18e32234d375444ffccbc5a8f0 /src/ee/xml | |
parent | effb3470dd1be3a0dd1eaa83991cef45b5e08dab (diff) | |
download | ee-python-0149fcfa2bd9ac8c9f6b05851f7264f005aa2305.tar.gz ee-python-0149fcfa2bd9ac8c9f6b05851f7264f005aa2305.tar.bz2 ee-python-0149fcfa2bd9ac8c9f6b05851f7264f005aa2305.tar.xz ee-python-0149fcfa2bd9ac8c9f6b05851f7264f005aa2305.zip |
drawio-to-parts: new tool.
ee.xsd: new type: Assembly and AssemblyPart. Should probably be its own
file type.
ee.part: Better DSL instead of using the raw xml types.
Diffstat (limited to 'src/ee/xml')
-rw-r--r-- | src/ee/xml/types.py | 357 |
1 files changed, 338 insertions, 19 deletions
diff --git a/src/ee/xml/types.py b/src/ee/xml/types.py index 8e5e39f..a6ef46b 100644 --- a/src/ee/xml/types.py +++ b/src/ee/xml/types.py @@ -3,7 +3,7 @@ # # Generated by generateDS.py. -# Python 3.7.2+ (default, Feb 2 2019, 14:31:48) [GCC 8.2.0] +# Python 3.7.3rc1 (default, Mar 13 2019, 11:01:15) [GCC 8.3.0] # # Command line options: # ('-f', '') @@ -729,10 +729,11 @@ def _cast(typ, value): class PartDb(GeneratedsSuper): subclass = None superclass = None - def __init__(self, parts=None, **kwargs_): + def __init__(self, parts=None, assembly=None, **kwargs_): self.original_tagname_ = None self.parent_object_ = kwargs_.get('parent_object_') self.parts = parts + self.assembly = assembly def factory(*args_, **kwargs_): if CurrentSubclassModule_ is not None: subclass = getSubclassFromModule_( @@ -749,9 +750,15 @@ class PartDb(GeneratedsSuper): def set_parts(self, parts): self.parts = parts partsProp = property(get_parts, set_parts) + def get_assembly(self): + return self.assembly + def set_assembly(self, assembly): + self.assembly = assembly + assemblyProp = property(get_assembly, set_assembly) def hasContent_(self): if ( - self.parts is not None + self.parts is not None or + self.assembly is not None ): return True else: @@ -786,6 +793,8 @@ class PartDb(GeneratedsSuper): eol_ = '' if self.parts is not None: self.parts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='parts', pretty_print=pretty_print) + if self.assembly is not None: + self.assembly.export(outfile, level, namespaceprefix_, namespacedef_='', name_='assembly', pretty_print=pretty_print) def build(self, node): already_processed = set() self.buildAttributes(node, node.attrib, already_processed) @@ -801,6 +810,11 @@ class PartDb(GeneratedsSuper): obj_.build(child_) self.parts = obj_ obj_.original_tagname_ = 'parts' + elif nodeName_ == 'assembly': + obj_ = Assembly.factory(parent_object_=self) + obj_.build(child_) + self.assembly = obj_ + obj_.original_tagname_ = 'assembly' # end class PartDb @@ -969,7 +983,7 @@ class Part(GeneratedsSuper): self.links = obj_ obj_.original_tagname_ = 'links' elif nodeName_ == 'references': - obj_ = ReferencesList.factory(parent_object_=self) + obj_ = ReferenceList.factory(parent_object_=self) obj_.build(child_) self.references = obj_ obj_.original_tagname_ = 'references' @@ -1392,10 +1406,10 @@ class SchematicReference(GeneratedsSuper): # end class SchematicReference -class ReferencesList(GeneratedsSuper): +class ReferenceList(GeneratedsSuper): subclass = None superclass = None - def __init__(self, part_reference=None, schematic_reference=None, part_number=None, supplier_part_number=None, **kwargs_): + def __init__(self, part_reference=None, schematic_reference=None, part_number=None, supplier_part_number=None, description=None, **kwargs_): self.original_tagname_ = None self.parent_object_ = kwargs_.get('parent_object_') if part_reference is None: @@ -1414,16 +1428,20 @@ class ReferencesList(GeneratedsSuper): self.supplier_part_number = [] else: self.supplier_part_number = supplier_part_number + if description is None: + self.description = [] + else: + self.description = description def factory(*args_, **kwargs_): if CurrentSubclassModule_ is not None: subclass = getSubclassFromModule_( - CurrentSubclassModule_, ReferencesList) + CurrentSubclassModule_, ReferenceList) if subclass is not None: return subclass(*args_, **kwargs_) - if ReferencesList.subclass: - return ReferencesList.subclass(*args_, **kwargs_) + if ReferenceList.subclass: + return ReferenceList.subclass(*args_, **kwargs_) else: - return ReferencesList(*args_, **kwargs_) + return ReferenceList(*args_, **kwargs_) factory = staticmethod(factory) def get_part_reference(self): return self.part_reference @@ -1477,18 +1495,32 @@ class ReferencesList(GeneratedsSuper): def replace_supplier_part_number_at(self, index, value): self.supplier_part_number[index] = value supplier_part_numberProp = property(get_supplier_part_number, set_supplier_part_number) + def get_description(self): + return self.description + def set_description(self, description): + self.description = description + def add_description(self, value): + self.description.append(value) + def add_description(self, value): + self.description.append(value) + def insert_description_at(self, index, value): + self.description.insert(index, value) + def replace_description_at(self, index, value): + self.description[index] = value + descriptionProp = property(get_description, set_description) def hasContent_(self): if ( self.part_reference or self.schematic_reference or self.part_number or - self.supplier_part_number + self.supplier_part_number or + self.description ): return True else: return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='ReferencesList', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('ReferencesList') + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='ReferenceList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('ReferenceList') if imported_ns_def_ is not None: namespacedef_ = imported_ns_def_ if pretty_print: @@ -1500,17 +1532,17 @@ class ReferencesList(GeneratedsSuper): 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_='ReferencesList') + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='ReferenceList') if self.hasContent_(): outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='ReferencesList', pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='ReferenceList', 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_='ReferencesList'): + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='ReferenceList'): pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='ReferencesList', fromsubclass_=False, pretty_print=True): + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='ReferenceList', fromsubclass_=False, pretty_print=True): if pretty_print: eol_ = '\n' else: @@ -1523,6 +1555,9 @@ class ReferencesList(GeneratedsSuper): part_number_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-number', pretty_print=pretty_print) for supplier_part_number_ in self.supplier_part_number: supplier_part_number_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='supplier-part-number', pretty_print=pretty_print) + for description_ in self.description: + showIndent(outfile, level, pretty_print) + outfile.write('<%sdescription>%s</%sdescription>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(description_), input_name='description')), namespaceprefix_ , eol_)) def build(self, node): already_processed = set() self.buildAttributes(node, node.attrib, already_processed) @@ -1553,7 +1588,11 @@ class ReferencesList(GeneratedsSuper): obj_.build(child_) self.supplier_part_number.append(obj_) obj_.original_tagname_ = 'supplier-part-number' -# end class ReferencesList + elif nodeName_ == 'description': + description_ = child_.text + description_ = self.gds_validate_string(description_, node, 'description') + self.description.append(description_) +# end class ReferenceList class Fact(GeneratedsSuper): @@ -2297,6 +2336,283 @@ class LinkList(GeneratedsSuper): # end class LinkList +class AssemblyPart(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, references=None, count=None, sub_parts=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.references = references + self.count = count + self.sub_parts = sub_parts + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, AssemblyPart) + if subclass is not None: + return subclass(*args_, **kwargs_) + if AssemblyPart.subclass: + return AssemblyPart.subclass(*args_, **kwargs_) + else: + return AssemblyPart(*args_, **kwargs_) + factory = staticmethod(factory) + def get_references(self): + return self.references + def set_references(self, references): + self.references = references + referencesProp = property(get_references, set_references) + def get_count(self): + return self.count + def set_count(self, count): + self.count = count + countProp = property(get_count, set_count) + def get_sub_parts(self): + return self.sub_parts + def set_sub_parts(self, sub_parts): + self.sub_parts = sub_parts + sub_partsProp = property(get_sub_parts, set_sub_parts) + def hasContent_(self): + if ( + self.references is not None or + self.count is not None or + self.sub_parts is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='AssemblyPart', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('AssemblyPart') + 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_='AssemblyPart') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='AssemblyPart', 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_='AssemblyPart'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='AssemblyPart', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.references is not None: + self.references.export(outfile, level, namespaceprefix_, namespacedef_='', name_='references', pretty_print=pretty_print) + if self.count is not None: + showIndent(outfile, level, pretty_print) + outfile.write('<%scount>%s</%scount>%s' % (namespaceprefix_ , self.gds_format_double(self.count, input_name='count'), namespaceprefix_ , eol_)) + if self.sub_parts is not None: + self.sub_parts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='sub-parts', 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_ == 'references': + obj_ = ReferenceList.factory(parent_object_=self) + obj_.build(child_) + self.references = obj_ + obj_.original_tagname_ = 'references' + elif nodeName_ == 'count' and child_.text: + sval_ = child_.text + try: + fval_ = float(sval_) + except (TypeError, ValueError) as exp: + raise_parse_error(child_, 'requires float or double: %s' % exp) + fval_ = self.gds_validate_float(fval_, node, 'count') + self.count = fval_ + elif nodeName_ == 'sub-parts': + obj_ = AssemblyPartList.factory(parent_object_=self) + obj_.build(child_) + self.sub_parts = obj_ + obj_.original_tagname_ = 'sub-parts' +# end class AssemblyPart + + +class AssemblyPartList(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, assembly_part=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + if assembly_part is None: + self.assembly_part = [] + else: + self.assembly_part = assembly_part + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, AssemblyPartList) + if subclass is not None: + return subclass(*args_, **kwargs_) + if AssemblyPartList.subclass: + return AssemblyPartList.subclass(*args_, **kwargs_) + else: + return AssemblyPartList(*args_, **kwargs_) + factory = staticmethod(factory) + def get_assembly_part(self): + return self.assembly_part + def set_assembly_part(self, assembly_part): + self.assembly_part = assembly_part + def add_assembly_part(self, value): + self.assembly_part.append(value) + def add_assembly_part(self, value): + self.assembly_part.append(value) + def insert_assembly_part_at(self, index, value): + self.assembly_part.insert(index, value) + def replace_assembly_part_at(self, index, value): + self.assembly_part[index] = value + assembly_partProp = property(get_assembly_part, set_assembly_part) + def hasContent_(self): + if ( + self.assembly_part + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='AssemblyPartList', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('AssemblyPartList') + 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_='AssemblyPartList') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='AssemblyPartList', 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_='AssemblyPartList'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='AssemblyPartList', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + for assembly_part_ in self.assembly_part: + assembly_part_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='assembly-part', 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_ == 'assembly-part': + obj_ = AssemblyPart.factory(parent_object_=self) + obj_.build(child_) + self.assembly_part.append(obj_) + obj_.original_tagname_ = 'assembly-part' +# end class AssemblyPartList + + +class Assembly(GeneratedsSuper): + subclass = None + superclass = None + def __init__(self, assembly_parts=None, **kwargs_): + self.original_tagname_ = None + self.parent_object_ = kwargs_.get('parent_object_') + self.assembly_parts = assembly_parts + def factory(*args_, **kwargs_): + if CurrentSubclassModule_ is not None: + subclass = getSubclassFromModule_( + CurrentSubclassModule_, Assembly) + if subclass is not None: + return subclass(*args_, **kwargs_) + if Assembly.subclass: + return Assembly.subclass(*args_, **kwargs_) + else: + return Assembly(*args_, **kwargs_) + factory = staticmethod(factory) + def get_assembly_parts(self): + return self.assembly_parts + def set_assembly_parts(self, assembly_parts): + self.assembly_parts = assembly_parts + assembly_partsProp = property(get_assembly_parts, set_assembly_parts) + def hasContent_(self): + if ( + self.assembly_parts is not None + ): + return True + else: + return False + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Assembly', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('Assembly') + 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_='Assembly') + if self.hasContent_(): + outfile.write('>%s' % (eol_, )) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='Assembly', 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_='Assembly'): + pass + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='Assembly', fromsubclass_=False, pretty_print=True): + if pretty_print: + eol_ = '\n' + else: + eol_ = '' + if self.assembly_parts is not None: + self.assembly_parts.export(outfile, level, namespaceprefix_, namespacedef_='', name_='assembly-parts', 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_ == 'assembly-parts': + obj_ = AssemblyPartList.factory(parent_object_=self) + obj_.build(child_) + self.assembly_parts = obj_ + obj_.original_tagname_ = 'assembly-parts' +# end class Assembly + + GDSClassesMapping = { 'part': Part, 'part-db': PartDb, @@ -2428,6 +2744,9 @@ if __name__ == '__main__': __all__ = [ "Amount", + "Assembly", + "AssemblyPart", + "AssemblyPartList", "DistributorInfo", "Fact", "FactList", @@ -2440,7 +2759,7 @@ __all__ = [ "PartReference", "PriceBreak", "PriceBreakList", - "ReferencesList", + "ReferenceList", "SchematicReference", "SupplierPartNumber" ] |