diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-15 10:55:06 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-03-15 10:55:06 +0100 |
commit | 3523190bb7ca1c38caea3a1aae51062d22e56b09 (patch) | |
tree | db975c27c38c873a012d88a266ad82621b0859b2 /src | |
parent | b67aa2b41247991e361dec0963670b4e5108410a (diff) | |
download | ee-python-3523190bb7ca1c38caea3a1aae51062d22e56b09.tar.gz ee-python-3523190bb7ca1c38caea3a1aae51062d22e56b09.tar.bz2 ee-python-3523190bb7ca1c38caea3a1aae51062d22e56b09.tar.xz ee-python-3523190bb7ca1c38caea3a1aae51062d22e56b09.zip |
o Switching PartDb to serialize into many xml files into a single
<part-db> document.
Diffstat (limited to 'src')
-rw-r--r-- | src/ee/digikey/normalize_facts.py | 8 | ||||
-rw-r--r-- | src/ee/digikey/search_parts.py | 8 | ||||
-rw-r--r-- | src/ee/element14/search_parts.py | 6 | ||||
-rw-r--r-- | src/ee/order/__init__.py | 6 | ||||
-rw-r--r-- | src/ee/part/__init__.py | 56 | ||||
-rw-r--r-- | src/ee/part/create_distributor_search_list.py | 8 | ||||
-rw-r--r-- | src/ee/tools/create_order.py | 2 | ||||
-rw-r--r-- | src/ee/tools/digikey_normalize_facts.py | 4 | ||||
-rw-r--r-- | src/ee/tools/digikey_search_parts.py | 9 | ||||
-rw-r--r-- | src/ee/tools/element14_search_parts.py | 8 | ||||
-rw-r--r-- | src/ee/tools/import_parts_yaml.py | 6 | ||||
-rw-r--r-- | src/ee/tools/kicad_make_bom.py | 3 | ||||
-rw-r--r-- | src/ee/tools/part_create_distributor_search_list.py | 8 | ||||
-rw-r--r-- | src/ee/tools/templates/build.ninja.j2 | 50 | ||||
-rw-r--r-- | src/ee/xml/types.py | 288 |
15 files changed, 91 insertions, 379 deletions
diff --git a/src/ee/digikey/normalize_facts.py b/src/ee/digikey/normalize_facts.py index 91e8c07..91ad4db 100644 --- a/src/ee/digikey/normalize_facts.py +++ b/src/ee/digikey/normalize_facts.py @@ -113,10 +113,8 @@ parsers: Mapping[int, Callable[[str], Any]] = { } -def normalize_facts(in_dir: Path, out_dir: Path): - print("in: {}, out: {}".format(in_dir, out_dir)) - - in_db = load_db(in_dir) +def normalize_facts(in_path: Path, out_path: Path): + in_db = load_db(in_path) out_parts = PartDb() for part in in_db.iterparts(): # type: types.Part @@ -155,4 +153,4 @@ def normalize_facts(in_dir: Path, out_dir: Path): out_parts.add_entry(part, True) print("Saving {} work parts".format(out_parts.size())) - save_db(out_dir, out_parts) + save_db(out_path, out_parts) diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py index 4203624..4f637c7 100644 --- a/src/ee/digikey/search_parts.py +++ b/src/ee/digikey/search_parts.py @@ -38,10 +38,8 @@ def resolved(p: DigikeyProduct) -> types.Part: return part -def search_parts(in_dir: Path, out_dir: Path, cache_dir: Path, force_refresh: bool): - print("in: {}, out: {}".format(in_dir, out_dir)) - - in_db = load_db(in_dir) +def search_parts(in_path: Path, out_path: Path, cache_dir: Path): + in_db = load_db(in_path) out_parts = PartDb() parser = DigikeyParser(Digikey()) @@ -103,4 +101,4 @@ def search_parts(in_dir: Path, out_dir: Path, cache_dir: Path, force_refresh: bo out_parts.add_entry(out_part, True) print("Saving {} work parts".format(out_parts.size())) - save_db(out_dir, out_parts) + save_db(out_path, out_parts) diff --git a/src/ee/element14/search_parts.py b/src/ee/element14/search_parts.py index 32abec1..55e8130 100644 --- a/src/ee/element14/search_parts.py +++ b/src/ee/element14/search_parts.py @@ -7,8 +7,8 @@ from ee.xml import bom_file_utils, types __all__ = ["search_parts"] -def search_parts(in_dir: Path, out_dir: Path, cache_dir: Path, config: Element14Config): - in_db = load_db(in_dir) +def search_parts(in_path: Path, out_path: Path, cache_dir: Path, config: Element14Config): + in_db = load_db(in_path) out_parts = PartDb() client = Element14Client(config, cache_dir) @@ -28,4 +28,4 @@ def search_parts(in_dir: Path, out_dir: Path, cache_dir: Path, config: Element14 di = out_part.distributor_infoProp print("Saving {} work parts".format(out_parts.size())) - save_db(out_dir, out_parts) + save_db(out_path, out_parts) diff --git a/src/ee/order/__init__.py b/src/ee/order/__init__.py index 368ea7a..5350667 100644 --- a/src/ee/order/__init__.py +++ b/src/ee/order/__init__.py @@ -20,8 +20,8 @@ class PartInfo(object): return self.part.idProp == other.part.idProp -def create_order(schematic_dir: Path, out_dir: Path, part_db_dirs: List[Path], fail_on_missing_parts: bool): - sch_db = load_db(schematic_dir) +def create_order(schematic_path: Path, out_path: Path, part_db_dirs: List[Path], fail_on_missing_parts: bool): + sch_db = load_db(schematic_path) dbs = [(path.parent.name, load_db(path)) for path in part_db_dirs] @@ -85,4 +85,4 @@ def create_order(schematic_dir: Path, out_dir: Path, part_db_dirs: List[Path], f out_parts.add_entry(part, True) print("Saving {} work parts".format(out_parts.size())) - save_db(out_dir, out_parts) + save_db(out_path, out_parts) diff --git a/src/ee/part/__init__.py b/src/ee/part/__init__.py index 27b6619..45561ec 100644 --- a/src/ee/part/__init__.py +++ b/src/ee/part/__init__.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import List, MutableMapping, Optional, Iterator from ee import EeException -from ee.xml import types +from ee.xml import types, bom_file_utils from ee.xml.bom_file_utils import find_pn, find_dpn, find_root_tag __all__ = [ @@ -62,52 +62,24 @@ class PartDb(object): return idx[pn].part -def load_db(dir_path: Path) -> PartDb: +def load_db(path: Path) -> PartDb: db = PartDb() - for file in dir_path.iterdir(): - if not file.is_file() or not file.name.endswith(".xml") or file.name == "index.xml": - continue + with path.open("r") as f: + part_db: types.PartDb = types.parse(f, silence=True) - part = types.parse(str(file), silence=True) # type: types.Part - db.add_entry(part, False) + part_db.partsProp = part_db.partsProp or types.PartList() - return db - - -def save_db(dir_path: Path, db: PartDb): - if dir_path.exists(): - if not dir_path.is_dir(): - raise EeException("The given db path is not a directory") - - idx_path = dir_path / "index.xml" - if not idx_path.is_file(): - # Ninja creates the parent directories out the output.. - if len(list(dir_path.iterdir())) > 0: - raise EeException("The given db directory exists, but does not look like a part db dir") + for p in part_db.partsProp.part: + db.add_entry(p, False) - for p in dir_path.iterdir(): - if not p.is_file(): - raise EeException("Non-file: {}".format(p)) - p.unlink() - dir_path.rmdir() - - dir_path.mkdir(parents=True, exist_ok=True) - - idx = types.IndexFile() - idx.filesProp = types.FileList() - files = idx.filesProp.fileProp - - parts = db.iterparts() - parts = sorted(parts, key=lambda p: p.idProp) + return db - for part in parts: - id_ = part.id - path = dir_path / "{}.xml".format(id_.replace("/", "_")) - with path.open("w") as f: - part.export(outfile=f, level=0, name_=find_root_tag(part)) - files.append(types.File(path=str(path))) +def save_db(path: Path, db: PartDb): + part_db = types.PartDb() + parts = part_db.parts = types.PartList() + parts.partProp.extend(db.iterparts(sort=True)) - with (dir_path / "index.xml").open("w") as f: - idx.export(f, level=0, name_=find_root_tag(idx)) + with path.open("w") as f: + part_db.export(outfile=f, level=0, name_=find_root_tag(part_db)) diff --git a/src/ee/part/create_distributor_search_list.py b/src/ee/part/create_distributor_search_list.py index bd5f69e..88e5a10 100644 --- a/src/ee/part/create_distributor_search_list.py +++ b/src/ee/part/create_distributor_search_list.py @@ -7,10 +7,8 @@ from ee.xml.bom_file_utils import * __all__ = ["create_distributor_search_list"] -def create_distributor_search_list(in_dir: Path, out_dir: Path): - print("in: {}, out: {}".format(in_dir, out_dir)) - - in_parts = load_db(in_dir) +def create_distributor_search_list(in_path: Path, out_path: Path): + in_parts = load_db(in_path) out_parts = PartDb() print("loaded {} existing parts".format(in_parts.size())) @@ -33,4 +31,4 @@ def create_distributor_search_list(in_dir: Path, out_dir: Path): out_parts.add_entry(new_part, True) print("Saving {} work parts".format(out_parts.size())) - save_db(out_dir, out_parts) + save_db(out_path, out_parts) diff --git a/src/ee/tools/create_order.py b/src/ee/tools/create_order.py index e0bed58..8ca7e05 100644 --- a/src/ee/tools/create_order.py +++ b/src/ee/tools/create_order.py @@ -12,7 +12,7 @@ parser.add_argument("--schematic", parser.add_argument("--out", required=True, - metavar="DIR") + metavar="PART DB") parser.add_argument("--part-db", nargs="*", diff --git a/src/ee/tools/digikey_normalize_facts.py b/src/ee/tools/digikey_normalize_facts.py index 07cc0d7..decf435 100644 --- a/src/ee/tools/digikey_normalize_facts.py +++ b/src/ee/tools/digikey_normalize_facts.py @@ -8,11 +8,11 @@ parser = argparse.ArgumentParser() parser.add_argument("--in", dest="in_", required=True, - metavar="FILE") + metavar="PART DB") parser.add_argument("--out", required=True, - metavar="FILE") + metavar="PART DB") args = parser.parse_args() diff --git a/src/ee/tools/digikey_search_parts.py b/src/ee/tools/digikey_search_parts.py index 07c3017..9f35e33 100644 --- a/src/ee/tools/digikey_search_parts.py +++ b/src/ee/tools/digikey_search_parts.py @@ -6,17 +6,16 @@ from ee.digikey.search_parts import search_parts parser = argparse.ArgumentParser() parser.add_argument("--in", - dest="in_", + dest="in_path", required=True, - metavar="FILE") + metavar="PART DB") parser.add_argument("--out", required=True, - metavar="FILE") + metavar="PART DB") args = parser.parse_args() cache_dir = ".ee/cache/digikey" -force = True -search_parts(Path(args.in_), Path(args.out), Path(cache_dir), force) +search_parts(Path(args.in_path), Path(args.out), Path(cache_dir)) diff --git a/src/ee/tools/element14_search_parts.py b/src/ee/tools/element14_search_parts.py index a4793c5..11fd3e1 100644 --- a/src/ee/tools/element14_search_parts.py +++ b/src/ee/tools/element14_search_parts.py @@ -8,13 +8,13 @@ from ee.element14.search_parts import search_parts parser = argparse.ArgumentParser() parser.add_argument("--in", - dest="in_", + dest="in_path", required=True, - metavar="FILE") + metavar="PART DB") parser.add_argument("--out", required=True, - metavar="FILE") + metavar="PART DB") args = parser.parse_args() @@ -27,4 +27,4 @@ e14_config = Element14Config( api_key=config.get("element14", "api-key", fallback=None) ) -search_parts(Path(args.in_), Path(args.out), Path(cache_dir), e14_config) +search_parts(Path(args.in_path), Path(args.out), Path(cache_dir), e14_config) diff --git a/src/ee/tools/import_parts_yaml.py b/src/ee/tools/import_parts_yaml.py index d13907e..9b8e3bf 100644 --- a/src/ee/tools/import_parts_yaml.py +++ b/src/ee/tools/import_parts_yaml.py @@ -39,14 +39,14 @@ def import_parts_yaml(in_file: Path, out_dir: Path): parser = argparse.ArgumentParser() parser.add_argument("--in", - dest="in_", + dest="in_path", required=True, metavar="PARTS_YAML") parser.add_argument("--out", required=True, - metavar="PART_ DB") + metavar="PART DB") args = parser.parse_args() -import_parts_yaml(Path(args.in_), Path(args.out)) +import_parts_yaml(Path(args.in_path), Path(args.out)) diff --git a/src/ee/tools/kicad_make_bom.py b/src/ee/tools/kicad_make_bom.py index c4a1dd8..60509a3 100644 --- a/src/ee/tools/kicad_make_bom.py +++ b/src/ee/tools/kicad_make_bom.py @@ -13,8 +13,7 @@ parser.add_argument("--sch", help="The schematic to read") parser.add_argument("--out", - metavar="FILE", - help="The output file") + metavar="PART DB") parser.add_argument("--strategy", metavar="FUNC") diff --git a/src/ee/tools/part_create_distributor_search_list.py b/src/ee/tools/part_create_distributor_search_list.py index 22b4c3f..273b6d3 100644 --- a/src/ee/tools/part_create_distributor_search_list.py +++ b/src/ee/tools/part_create_distributor_search_list.py @@ -6,14 +6,14 @@ from ee.part.create_distributor_search_list import create_distributor_search_lis parser = argparse.ArgumentParser() parser.add_argument("--in", - dest="in_", + dest="in_path", required=True, - metavar="FILE") + metavar="PART DB") parser.add_argument("--out", required=True, - metavar="FILE") + metavar="PART DB") args = parser.parse_args() -create_distributor_search_list(Path(args.in_), Path(args.out)) +create_distributor_search_list(Path(args.in_path), Path(args.out)) diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2 index e91de6c..8552d96 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -13,36 +13,36 @@ rule kicad-gerber # mv $(GERBER_DIR)/tmp.zip $@ rule kicad-make-bom - description = kicad-make-bom $out_dir - command = $ee kicad-make-bom --sch $sch --out $out_dir $strategy + description = kicad-make-bom $out + command = $ee kicad-make-bom --sch $sch --out $out $strategy rule part-create-distributor-search-list - description = part-create-distributor-search-list distributor=$distributor $in_dir => $out_dir - command = $ee part-create-distributor-search-list --in $in_dir --out $out_dir + description = part-create-distributor-search-list distributor: $distributor + command = $ee part-create-distributor-search-list --in $in --out $out rule digikey-search-parts description = digikey-search-parts - command = $ee digikey-search-parts --in $in_dir --out $out_dir + command = $ee digikey-search-parts --in $in --out $out rule digikey-normalize-facts description = digikey-normalize-facts - command = $ee digikey-normalize-facts --in $in_dir --out $out_dir + command = $ee digikey-normalize-facts --in $in --out $out rule element14-search-parts description = element14-search-parts - command = $ee element14-search-parts --in $in_dir --out $out_dir + command = $ee element14-search-parts --in $in --out $out rule element14-normalize-facts description = element14-normalize-facts - command = $ee element14-normalize-facts --in $in_dir --out $out_dir + command = $ee element14-normalize-facts --in $in --out $out rule create-order description = create-order - command = $ee create-order --schematic $sch_dir --part-db $part_dbs --out $out_dir + command = $ee create-order --schematic $schematic --part-db $part_dbs --out $out rule import-parts-yaml description = import-parts-yaml $in - command = $ee import-parts-yaml --in $in --out $out_dir + command = $ee import-parts-yaml --in $in --out $out {% if gerber_zip is defined %} build gerbers: phony {{ gerber_zip }} @@ -50,37 +50,29 @@ build {{ gerber_zip }}: kicad-gerber $pcb gerber_dir = {{ gerber_zip | parent_dir }} {%- endif %} -build ee/sch/index.xml: kicad-make-bom $sch - out_dir = ee/sch +build ee/sch.xml: kicad-make-bom $sch strategy = {{ "--strategy " + kicad_bom_strategy if kicad_bom_strategy else "" }} {%- for d in distributors %} # Distributor {{ d }} -build ee/{{ d }}/search-list/index.xml: part-create-distributor-search-list ee/sch/index.xml - in_dir = ee/sch - out_dir = ee/{{ d }}/search-list +build ee/{{ d }}/search-list.xml: part-create-distributor-search-list ee/sch.xml + distributor = {{ d }} -build ee/{{ d }}/downloaded/index.xml: {{ d }}-search-parts ee/{{ d }}/search-list/index.xml - in_dir = ee/{{ d }}/search-list - out_dir = ee/{{ d }}/downloaded +build ee/{{ d }}/downloaded.xml: {{ d }}-search-parts ee/{{ d }}/search-list.xml -build ee/{{ d }}/normalized/index.xml: {{ d }}-normalize-facts ee/{{ d }}/downloaded/index.xml - in_dir = ee/{{ d }}/downloaded - out_dir = ee/{{ d }}/normalized +build ee/{{ d }}/normalized.xml: {{ d }}-normalize-facts ee/{{ d }}/downloaded.xml -default ee/{{ d }}/normalized/index.xml +default ee/{{ d }}/normalized.xml {%- endfor %} {%- for f in parts_yaml_files %} -{% set out=(f | parent_dir) / (f | noext) / "index.xml" %} +{% set out=(f | parent_dir) / ((f | noext) + ".xml") %} build {{ out }}: import-parts-yaml {{ f }} - out_dir = {{ f | parent_dir }}/{{ f | noext }} # default {{ out }} {% endfor %} -build ee/order/index.xml: create-order ee/sch/index.xml {%- for p in part_dbs %} {{ p / "index.xml" }}{% endfor %} - sch_dir = ee/sch - out_dir = ee/order - part_dbs ={%- for p in part_dbs %} {{ p }}{% endfor %} +build ee/order.xml: create-order ee/sch.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %} + schematic = ee/sch.xml + part_dbs ={%- for p in part_dbs %} {{ p }}.xml{% endfor %} -default ee/order/index.xml +default ee/order.xml diff --git a/src/ee/xml/types.py b/src/ee/xml/types.py index 356b520..fec6884 100644 --- a/src/ee/xml/types.py +++ b/src/ee/xml/types.py @@ -726,7 +726,7 @@ def _cast(typ, value): # -class PartCollection(GeneratedsSuper): +class PartDb(GeneratedsSuper): subclass = None superclass = None def __init__(self, parts=None, **kwargs_): @@ -736,13 +736,13 @@ class PartCollection(GeneratedsSuper): def factory(*args_, **kwargs_): if CurrentSubclassModule_ is not None: subclass = getSubclassFromModule_( - CurrentSubclassModule_, PartCollection) + CurrentSubclassModule_, PartDb) if subclass is not None: return subclass(*args_, **kwargs_) - if PartCollection.subclass: - return PartCollection.subclass(*args_, **kwargs_) + if PartDb.subclass: + return PartDb.subclass(*args_, **kwargs_) else: - return PartCollection(*args_, **kwargs_) + return PartDb(*args_, **kwargs_) factory = staticmethod(factory) def get_parts(self): return self.parts @@ -756,8 +756,8 @@ class PartCollection(GeneratedsSuper): return True else: return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartCollection', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartCollection') + def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartDb', pretty_print=True): + imported_ns_def_ = GenerateDSNamespaceDefs_.get('PartDb') if imported_ns_def_ is not None: namespacedef_ = imported_ns_def_ if pretty_print: @@ -769,17 +769,17 @@ class PartCollection(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_='PartCollection') + self.exportAttributes(outfile, level, already_processed, namespaceprefix_, name_='PartDb') if self.hasContent_(): outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartCollection', pretty_print=pretty_print) + self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='PartDb', 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_='PartCollection'): + def exportAttributes(self, outfile, level, already_processed, namespaceprefix_='', name_='PartDb'): pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartCollection', fromsubclass_=False, pretty_print=True): + def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='PartDb', fromsubclass_=False, pretty_print=True): if pretty_print: eol_ = '\n' else: @@ -801,7 +801,7 @@ class PartCollection(GeneratedsSuper): obj_.build(child_) self.parts = obj_ obj_.original_tagname_ = 'parts' -# end class PartCollection +# end class PartDb class Part(GeneratedsSuper): @@ -1773,250 +1773,9 @@ class PriceBreakList(GeneratedsSuper): # end class PriceBreakList -class IndexFile(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, files=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.files = files - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, IndexFile) - if subclass is not None: - return subclass(*args_, **kwargs_) - if IndexFile.subclass: - return IndexFile.subclass(*args_, **kwargs_) - else: - return IndexFile(*args_, **kwargs_) - factory = staticmethod(factory) - def get_files(self): - return self.files - def set_files(self, files): - self.files = files - filesProp = property(get_files, set_files) - def hasContent_(self): - if ( - self.files is not None - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='IndexFile', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('IndexFile') - 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_='IndexFile') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='IndexFile', 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_='IndexFile'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='IndexFile', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - if self.files is not None: - self.files.export(outfile, level, namespaceprefix_, namespacedef_='', name_='files', 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_ == 'files': - obj_ = FileList.factory(parent_object_=self) - obj_.build(child_) - self.files = obj_ - obj_.original_tagname_ = 'files' -# end class IndexFile - - -class File(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, path=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - self.path = _cast(None, path) - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, File) - if subclass is not None: - return subclass(*args_, **kwargs_) - if File.subclass: - return File.subclass(*args_, **kwargs_) - else: - return File(*args_, **kwargs_) - factory = staticmethod(factory) - def get_path(self): - return self.path - def set_path(self, path): - self.path = path - pathProp = property(get_path, set_path) - def hasContent_(self): - if ( - - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='File', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('File') - 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_='File') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='File', 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_='File'): - if self.path is not None and 'path' not in already_processed: - already_processed.add('path') - outfile.write(' path=%s' % (self.gds_encode(self.gds_format_string(quote_attrib(self.path), input_name='path')), )) - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='File', 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_('path', node) - if value is not None and 'path' not in already_processed: - already_processed.add('path') - self.path = value - def buildChildren(self, child_, node, nodeName_, fromsubclass_=False): - pass -# end class File - - -class FileList(GeneratedsSuper): - subclass = None - superclass = None - def __init__(self, file=None, **kwargs_): - self.original_tagname_ = None - self.parent_object_ = kwargs_.get('parent_object_') - if file is None: - self.file = [] - else: - self.file = file - def factory(*args_, **kwargs_): - if CurrentSubclassModule_ is not None: - subclass = getSubclassFromModule_( - CurrentSubclassModule_, FileList) - if subclass is not None: - return subclass(*args_, **kwargs_) - if FileList.subclass: - return FileList.subclass(*args_, **kwargs_) - else: - return FileList(*args_, **kwargs_) - factory = staticmethod(factory) - def get_file(self): - return self.file - def set_file(self, file): - self.file = file - def add_file(self, value): - self.file.append(value) - def add_file(self, value): - self.file.append(value) - def insert_file_at(self, index, value): - self.file.insert(index, value) - def replace_file_at(self, index, value): - self.file[index] = value - fileProp = property(get_file, set_file) - def hasContent_(self): - if ( - self.file - ): - return True - else: - return False - def export(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FileList', pretty_print=True): - imported_ns_def_ = GenerateDSNamespaceDefs_.get('FileList') - 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_='FileList') - if self.hasContent_(): - outfile.write('>%s' % (eol_, )) - self.exportChildren(outfile, level + 1, namespaceprefix_, namespacedef_, name_='FileList', 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_='FileList'): - pass - def exportChildren(self, outfile, level, namespaceprefix_='', namespacedef_='', name_='FileList', fromsubclass_=False, pretty_print=True): - if pretty_print: - eol_ = '\n' - else: - eol_ = '' - for file_ in self.file: - file_.export(outfile, level, namespaceprefix_, namespacedef_='', name_='file', 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_ == 'file': - obj_ = File.factory(parent_object_=self) - obj_.build(child_) - self.file.append(obj_) - obj_.original_tagname_ = 'file' -# end class FileList - - GDSClassesMapping = { - 'file-index': IndexFile, 'part': Part, - 'part-collection': PartCollection, + 'part-db': PartDb, } @@ -2044,8 +1803,8 @@ def parse(inFileName, silence=False): rootNode = doc.getroot() rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: - rootTag = 'PartCollection' - rootClass = PartCollection + rootTag = 'PartDb' + rootClass = PartDb rootObj = rootClass.factory() rootObj.build(rootNode) # Enable Python to collect the space used by the DOM. @@ -2065,8 +1824,8 @@ def parseEtree(inFileName, silence=False): rootNode = doc.getroot() rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: - rootTag = 'PartCollection' - rootClass = PartCollection + rootTag = 'PartDb' + rootClass = PartDb rootObj = rootClass.factory() rootObj.build(rootNode) # Enable Python to collect the space used by the DOM. @@ -2096,8 +1855,8 @@ def parseString(inString, silence=False): rootNode= parsexmlstring_(inString, parser) rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: - rootTag = 'PartCollection' - rootClass = PartCollection + rootTag = 'PartDb' + rootClass = PartDb rootObj = rootClass.factory() rootObj.build(rootNode) # Enable Python to collect the space used by the DOM. @@ -2115,8 +1874,8 @@ def parseLiteral(inFileName, silence=False): rootNode = doc.getroot() rootTag, rootClass = get_root_tag(rootNode) if rootClass is None: - rootTag = 'PartCollection' - rootClass = PartCollection + rootTag = 'PartDb' + rootClass = PartDb rootObj = rootClass.factory() rootObj.build(rootNode) # Enable Python to collect the space used by the DOM. @@ -2148,11 +1907,8 @@ __all__ = [ "DistributorInfo", "Fact", "FactList", - "File", - "FileList", - "IndexFile", "Part", - "PartCollection", + "PartDb", "PartList", "PartNumber", "PartNumberList", |