aboutsummaryrefslogtreecommitdiff
path: root/src/ee/xml
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-03-28 16:38:50 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-03-28 16:43:14 +0100
commitfa85d46af0b91477cf354947df628af0dc0d2800 (patch)
treeb18b775d232560f57eaeb3f43d0861b98201d4ef /src/ee/xml
parent52401b170d8f1c9deaa153acca76e7d6060a06df (diff)
downloadee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.gz
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.bz2
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.xz
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.zip
ee.xsd:
o Renaming <part-uri> to <part-reference>. o Adding <supplier> on <part>, removing from <supplier-part-number>. A part can have exactly one part. create-order: o Creating anonymous part objects, with two references, one schematic reference and one part-uri reference to the selected part. o Redoing how the order is calculated with the new ObjDb structure. ee.part.Part: o Absorbing bom_file_utils into Part. Much better wrapper object around the xml goop.
Diffstat (limited to 'src/ee/xml')
-rw-r--r--src/ee/xml/bom_file_utils.py49
-rw-r--r--src/ee/xml/types.py144
2 files changed, 72 insertions, 121 deletions
diff --git a/src/ee/xml/bom_file_utils.py b/src/ee/xml/bom_file_utils.py
deleted file mode 100644
index 97b609f..0000000
--- a/src/ee/xml/bom_file_utils.py
+++ /dev/null
@@ -1,49 +0,0 @@
-from typing import List, Optional
-
-from ee.xml import types
-
-__all__ = [
- "facts",
- "find_root_tag",
- "schematic_references",
- "part_numbers",
- "supplier_part_numbers",
-]
-
-
-def find_root_tag(root):
- return next((tag for tag, klass in types.GDSClassesMapping.items() if klass == type(root)), None)
-
-
-def schematic_references(part: types.Part) -> List[types.SchematicReference]:
- return [] if part.referencesProp is None or part.referencesProp.schematic_reference is None else \
- part.referencesProp.schematic_reference
-
-
-def part_numbers(part: types.Part) -> List[types.PartNumber]:
- return [] if part.referencesProp is None or part.referencesProp.part_number is None else \
- part.referencesProp.part_number
-
-
-def supplier_part_numbers(part: types.Part) -> List[types.SupplierPartNumber]:
- return [] if part.referencesProp is None or part.referencesProp.supplier_part_number is None else \
- part.referencesProp.supplier_part_number
-
-
-def facts(part: types.Part, create=False) -> Optional[types.FactList]:
- fs: types.FactList = part.factsProp
-
- if fs is not None:
- return fs
-
- if not create:
- return
-
- fs = types.FactList()
- part.factsProp = fs
- return fs
-
-
-def find_fact(fs: types.FactList, key: str) -> Optional[types.Fact]:
- l: List[types.Fact] = fs.factProp
- return next((f for f in l if f.keyProp == key), None)
diff --git a/src/ee/xml/types.py b/src/ee/xml/types.py
index 60d659d..8e5e39f 100644
--- a/src/ee/xml/types.py
+++ b/src/ee/xml/types.py
@@ -807,10 +807,11 @@ class PartDb(GeneratedsSuper):
class Part(GeneratedsSuper):
subclass = None
superclass = None
- def __init__(self, uri=None, part_type=None, description=None, links=None, references=None, distributor_info=None, facts=None, price_breaks=None, **kwargs_):
+ def __init__(self, uri=None, supplier=None, part_type=None, description=None, links=None, references=None, distributor_info=None, facts=None, price_breaks=None, **kwargs_):
self.original_tagname_ = None
self.parent_object_ = kwargs_.get('parent_object_')
self.uri = _cast(None, uri)
+ self.supplier = supplier
self.part_type = part_type
self.description = description
self.links = links
@@ -829,6 +830,11 @@ class Part(GeneratedsSuper):
else:
return Part(*args_, **kwargs_)
factory = staticmethod(factory)
+ def get_supplier(self):
+ return self.supplier
+ def set_supplier(self, supplier):
+ self.supplier = supplier
+ supplierProp = property(get_supplier, set_supplier)
def get_part_type(self):
return self.part_type
def set_part_type(self, part_type):
@@ -871,6 +877,7 @@ class Part(GeneratedsSuper):
uriProp = property(get_uri, set_uri)
def hasContent_(self):
if (
+ self.supplier is not None or
self.part_type is not None or
self.description is not None or
self.links is not None or
@@ -912,6 +919,9 @@ class Part(GeneratedsSuper):
eol_ = '\n'
else:
eol_ = ''
+ if self.supplier is not None:
+ showIndent(outfile, level, pretty_print)
+ outfile.write('<%ssupplier>%s</%ssupplier>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.supplier), input_name='supplier')), namespaceprefix_ , eol_))
if self.part_type is not None:
showIndent(outfile, level, pretty_print)
outfile.write('<%spart-type>%s</%spart-type>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.part_type), input_name='part-type')), namespaceprefix_ , eol_))
@@ -941,7 +951,11 @@ class Part(GeneratedsSuper):
already_processed.add('uri')
self.uri = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
- if nodeName_ == 'part-type':
+ if nodeName_ == 'supplier':
+ supplier_ = child_.text
+ supplier_ = self.gds_validate_string(supplier_, node, 'supplier')
+ self.supplier = supplier_
+ elif nodeName_ == 'part-type':
part_type_ = child_.text
part_type_ = self.gds_validate_string(part_type_, node, 'part_type')
self.part_type = part_type_
@@ -1066,38 +1080,38 @@ class PartList(GeneratedsSuper):
# end class PartList
-class PartUri(GeneratedsSuper):
+class PartReference(GeneratedsSuper):
subclass = None
superclass = None
- def __init__(self, value=None, **kwargs_):
+ def __init__(self, part_uri=None, **kwargs_):
self.original_tagname_ = None
self.parent_object_ = kwargs_.get('parent_object_')
- self.value = value
+ self.part_uri = part_uri
def factory(*args_, **kwargs_):
if CurrentSubclassModule_ is not None:
subclass = getSubclassFromModule_(
- CurrentSubclassModule_, PartUri)
+ CurrentSubclassModule_, PartReference)
if subclass is not None:
return subclass(*args_, **kwargs_)
- if PartUri.subclass:
- return PartUri.subclass(*args_, **kwargs_)
+ if PartReference.subclass:
+ return PartReference.subclass(*args_, **kwargs_)
else:
- return PartUri(*args_, **kwargs_)
+ return PartReference(*args_, **kwargs_)
factory = staticmethod(factory)
- def get_value(self):
- return self.value
- def set_value(self, value):
- self.value = value
- valueProp = property(get_value, set_value)
+ def get_part_uri(self):
+ return self.part_uri
+ def set_part_uri(self, part_uri):
+ self.part_uri = part_uri
+ part_uriProp = property(get_part_uri, set_part_uri)
def hasContent_(self):
if (
- self.value is not None
+ self.part_uri is not None
):
return True
else:
return False
- def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartUri', pretty_print=True):
- imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartUri')
+ def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartReference', pretty_print=True):
+ imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartReference')
if imported_ns_def_ is not None:
namespacedef_ = imported_ns_def_
if pretty_print:
@@ -1109,24 +1123,24 @@ class PartUri(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_='PartUri')
+ self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartReference')
if self.hasContent_():
outfile.write('>%s' % (eol_, ))
- self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartUri', pretty_print=pretty_print)
+ self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartReference', 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_='PartUri'):
+ def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartReference'):
pass
- def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartUri', fromsubclass_=False, pretty_print=True):
+ def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartReference', fromsubclass_=False, pretty_print=True):
if pretty_print:
eol_ = '\n'
else:
eol_ = ''
- if self.value is not None:
+ if self.part_uri is not None:
showIndent(outfile, level, pretty_print)
- outfile.write('<%svalue>%s</%svalue>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.value), input_name='value')), namespaceprefix_ , eol_))
+ outfile.write('<%spart-uri>%s</%spart-uri>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.part_uri), input_name='part-uri')), namespaceprefix_ , eol_))
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
@@ -1137,11 +1151,11 @@ class PartUri(GeneratedsSuper):
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
- if nodeName_ == 'value':
- value_ = child_.text
- value_ = self.gds_validate_string(value_, node, 'value')
- self.value = value_
-# end class PartUri
+ if nodeName_ == 'part-uri':
+ part_uri_ = child_.text
+ part_uri_ = self.gds_validate_string(part_uri_, node, 'part_uri')
+ self.part_uri = part_uri_
+# end class PartReference
class PartNumber(GeneratedsSuper):
@@ -1225,11 +1239,10 @@ class PartNumber(GeneratedsSuper):
class SupplierPartNumber(GeneratedsSuper):
subclass = None
superclass = None
- def __init__(self, value=None, supplier=None, **kwargs_):
+ def __init__(self, value=None, **kwargs_):
self.original_tagname_ = None
self.parent_object_ = kwargs_.get('parent_object_')
self.value = value
- self.supplier = supplier
def factory(*args_, **kwargs_):
if CurrentSubclassModule_ is not None:
subclass = getSubclassFromModule_(
@@ -1246,15 +1259,9 @@ class SupplierPartNumber(GeneratedsSuper):
def set_value(self, value):
self.value = value
valueProp = property(get_value, set_value)
- def get_supplier(self):
- return self.supplier
- def set_supplier(self, supplier):
- self.supplier = supplier
- supplierProp = property(get_supplier, set_supplier)
def hasContent_(self):
if (
- self.value is not None or
- self.supplier is not None
+ self.value is not None
):
return True
else:
@@ -1290,9 +1297,6 @@ class SupplierPartNumber(GeneratedsSuper):
if self.value is not None:
showIndent(outfile, level, pretty_print)
outfile.write('<%svalue>%s</%svalue>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.value), input_name='value')), namespaceprefix_ , eol_))
- if self.supplier is not None:
- showIndent(outfile, level, pretty_print)
- outfile.write('<%ssupplier>%s</%ssupplier>%s' % (namespaceprefix_ , self.gds_encode(self.gds_format_string(quote_xml(self.supplier), input_name='supplier')), namespaceprefix_ , eol_))
def build(self, node):
already_processed = set()
self.buildAttributes(node, node.attrib, already_processed)
@@ -1307,10 +1311,6 @@ class SupplierPartNumber(GeneratedsSuper):
value_ = child_.text
value_ = self.gds_validate_string(value_, node, 'value')
self.value = value_
- elif nodeName_ == 'supplier':
- supplier_ = child_.text
- supplier_ = self.gds_validate_string(supplier_, node, 'supplier')
- self.supplier = supplier_
# end class SupplierPartNumber
@@ -1395,17 +1395,17 @@ class SchematicReference(GeneratedsSuper):
class ReferencesList(GeneratedsSuper):
subclass = None
superclass = None
- def __init__(self, schematic_reference=None, part_uri=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, **kwargs_):
self.original_tagname_ = None
self.parent_object_ = kwargs_.get('parent_object_')
+ if part_reference is None:
+ self.part_reference = []
+ else:
+ self.part_reference = part_reference
if schematic_reference is None:
self.schematic_reference = []
else:
self.schematic_reference = schematic_reference
- if part_uri is None:
- self.part_uri = []
- else:
- self.part_uri = part_uri
if part_number is None:
self.part_number = []
else:
@@ -1425,6 +1425,19 @@ class ReferencesList(GeneratedsSuper):
else:
return ReferencesList(*args_, **kwargs_)
factory = staticmethod(factory)
+ def get_part_reference(self):
+ return self.part_reference
+ def set_part_reference(self, part_reference):
+ self.part_reference = part_reference
+ def add_part_reference(self, value):
+ self.part_reference.append(value)
+ def add_part_reference(self, value):
+ self.part_reference.append(value)
+ def insert_part_reference_at(self, index, value):
+ self.part_reference.insert(index, value)
+ def replace_part_reference_at(self, index, value):
+ self.part_reference[index] = value
+ part_referenceProp = property(get_part_reference, set_part_reference)
def get_schematic_reference(self):
return self.schematic_reference
def set_schematic_reference(self, schematic_reference):
@@ -1438,19 +1451,6 @@ class ReferencesList(GeneratedsSuper):
def replace_schematic_reference_at(self, index, value):
self.schematic_reference[index] = value
schematic_referenceProp = property(get_schematic_reference, set_schematic_reference)
- def get_part_uri(self):
- return self.part_uri
- def set_part_uri(self, part_uri):
- self.part_uri = part_uri
- def add_part_uri(self, value):
- self.part_uri.append(value)
- def add_part_uri(self, value):
- self.part_uri.append(value)
- def insert_part_uri_at(self, index, value):
- self.part_uri.insert(index, value)
- def replace_part_uri_at(self, index, value):
- self.part_uri[index] = value
- part_uriProp = property(get_part_uri, set_part_uri)
def get_part_number(self):
return self.part_number
def set_part_number(self, part_number):
@@ -1479,8 +1479,8 @@ class ReferencesList(GeneratedsSuper):
supplier_part_numberProp = property(get_supplier_part_number, set_supplier_part_number)
def hasContent_(self):
if (
+ self.part_reference or
self.schematic_reference or
- self.part_uri or
self.part_number or
self.supplier_part_number
):
@@ -1515,10 +1515,10 @@ class ReferencesList(GeneratedsSuper):
eol_ = '\n'
else:
eol_ = ''
+ for part_reference_ in self.part_reference:
+ part_reference_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-reference', pretty_print=pretty_print)
for schematic_reference_ in self.schematic_reference:
schematic_reference_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='schematic-reference', pretty_print=pretty_print)
- for part_uri_ in self.part_uri:
- part_uri_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-uri', pretty_print=pretty_print)
for part_number_ in self.part_number:
part_number_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='part-number', pretty_print=pretty_print)
for supplier_part_number_ in self.supplier_part_number:
@@ -1533,16 +1533,16 @@ class ReferencesList(GeneratedsSuper):
def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
- if nodeName_ == 'schematic-reference':
+ if nodeName_ == 'part-reference':
+ obj_ = PartReference.factory(parent_object_=self)
+ obj_.build(child_)
+ self.part_reference.append(obj_)
+ obj_.original_tagname_ = 'part-reference'
+ elif nodeName_ == 'schematic-reference':
obj_ = SchematicReference.factory(parent_object_=self)
obj_.build(child_)
self.schematic_reference.append(obj_)
obj_.original_tagname_ = 'schematic-reference'
- elif nodeName_ == 'part-uri':
- obj_ = PartUri.factory(parent_object_=self)
- obj_.build(child_)
- self.part_uri.append(obj_)
- obj_.original_tagname_ = 'part-uri'
elif nodeName_ == 'part-number':
obj_ = PartNumber.factory(parent_object_=self)
obj_.build(child_)
@@ -2437,7 +2437,7 @@ __all__ = [
"PartDb",
"PartList",
"PartNumber",
- "PartUri",
+ "PartReference",
"PriceBreak",
"PriceBreakList",
"ReferencesList",