diff options
Diffstat (limited to 'src/ee/tools')
-rw-r--r-- | src/ee/tools/kicad_make_bom.py | 4 | ||||
-rw-r--r-- | src/ee/tools/part_apply_function.py | 67 | ||||
-rw-r--r-- | src/ee/tools/part_find_requirements.py | 39 | ||||
-rw-r--r-- | src/ee/tools/templates/build.ninja.j2 | 21 |
4 files changed, 124 insertions, 7 deletions
diff --git a/src/ee/tools/kicad_make_bom.py b/src/ee/tools/kicad_make_bom.py index 60509a3..0e36c6d 100644 --- a/src/ee/tools/kicad_make_bom.py +++ b/src/ee/tools/kicad_make_bom.py @@ -22,6 +22,4 @@ args = parser.parse_args() new_mode = True -strategy = args.strategy if args.strategy else "ee.kicad.make_bom.MakeBomStrategy" - -make_bom(Path(args.sch), Path(args.out), strategy, new_mode, pretty) +make_bom(Path(args.sch), Path(args.out), new_mode, pretty) diff --git a/src/ee/tools/part_apply_function.py b/src/ee/tools/part_apply_function.py new file mode 100644 index 0000000..bece364 --- /dev/null +++ b/src/ee/tools/part_apply_function.py @@ -0,0 +1,67 @@ +import argparse +import pydoc +from pathlib import Path +from typing import List + +from ee import tools, EeException +from ee.part import Part, PartDb, load_db, save_db +from ee.project import Project + + +def load_functions(function_names): + functions = [] + for fn in function_names: + f = pydoc.locate(fn) + + if f is None: + raise EeException("Could not load function: {}".format(fn)) + + if not callable(f): + raise EeException("Not a callable: {}, is a {}".format(fn, type(f))) + + functions.append((fn, f)) + return functions + + +def work(in_path: Path, out_path: Path, report_path: Path, function_names: List[str]): + functions = load_functions(function_names) + + in_parts = load_db(in_path) + + parts = PartDb() + + tools.mk_parents(report_path) + with report_path.open("w") as rpt: + for xml in in_parts.iterparts(): + part = Part(xml) + + for name, f in functions: + part = f(part) + + save_db(out_path, in_parts) + + +parser = argparse.ArgumentParser() + +parser.add_argument("--in", + dest="in_path", + required=True, + metavar="PART DB") + +parser.add_argument("--out", + required=True, + metavar="REQUIREMENTS") + +parser.add_argument("--function", + required=True, + nargs="*", + metavar="FUNCTION") + +parser.add_argument("--execution", + default="default") + +args = parser.parse_args() + +project = Project.load() +report = project.report_dir / "apply-function" / (args.execution + ".rst") +work(Path(args.in_path), Path(args.out), report, args.function) diff --git a/src/ee/tools/part_find_requirements.py b/src/ee/tools/part_find_requirements.py new file mode 100644 index 0000000..032db02 --- /dev/null +++ b/src/ee/tools/part_find_requirements.py @@ -0,0 +1,39 @@ +import argparse +from pathlib import Path + +from ee.part import requirement, Part, PartDb, load_db, save_db + + +def work(in_path: Path, out_path: Path): + in_parts = load_db(in_path) + + with out_path.open("w") as f: + print("<root>", file=f) + for xml in in_parts.iterparts(): + part = Part(xml) + + analysis = requirement.analyze_requirements(part) + + print("Part: {}. Found {} requirements".format(analysis.part.printable_reference, + len(analysis.requirements)), file=f) + + for r in analysis.requirements: + print(" {}".format(r), file=f) + + print("</root>", file=f) + + +parser = argparse.ArgumentParser() + +parser.add_argument("--in", + dest="in_path", + required=True, + metavar="PART DB") + +parser.add_argument("--out", + required=True, + metavar="REQUIREMENTS") + +args = parser.parse_args() + +work(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 76da4cf..1f9ba35 100644 --- a/src/ee/tools/templates/build.ninja.j2 +++ b/src/ee/tools/templates/build.ninja.j2 @@ -19,12 +19,19 @@ rule kicad-gerber rule kicad-make-bom description = kicad-make-bom $out - command = $ee kicad-make-bom --sch $sch --out $out $strategy + command = $ee kicad-make-bom --sch $sch --out $out rule pn-part-search-list description = pn-part-search-list supplier: $supplier command = $ee pn-part-search-list --in $in --out $out --supplier $supplier +rule part-apply-function + command = $ee part-apply-function --in $in --out $out $functions + +rule part-find-requirements + description = part-find-requirements + command = $ee part-find-requirements --in $in --out $out + rule digikey-search-parts description = digikey-search-parts command = $ee digikey-search-parts --in $in --out $out @@ -69,11 +76,17 @@ build {{ gerber_zip }}: kicad-gerber $pcb {%- endif %} {% if sch is defined -%} -build ee/sch.xml: kicad-make-bom $sch -{%- if project.cfg["kicad-project"]["strategy"] %} - strategy = --strategy {{ project.cfg["kicad-project"]["strategy"] }} +build ee/kicad-sch.xml: kicad-make-bom $sch +build ee/sch.xml: part-apply-function ee/kicad-sch.xml +{%- if project.cfg["kicad-project"]["functions"] %} + functions = --function {{ project.cfg["kicad-project"]["functions"] }} +{%- else %} + functions = --function ee.kicad.functions.default {%- endif %} {%- endif %} + +build ee/requirements.xml: part-find-requirements ee/sch.xml + {% for s in distributors %} # Supplier {{ s }} build ee/{{ s }}/pn-part-search-list.xml: pn-part-search-list ee/sch.xml |