From 9eba62ef1d6b4896de693976116f69a9692332d9 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 20 May 2019 15:27:38 +0200 Subject: ee: o Adding FactType as a smaller wrapper around the fact uri. o Adding ee.part.Facts, used as Part.facts o Renaming 'type' uri to 'ee-component-type'. kicad-make-bom: Removing strategy functionality, replaced with part-apply-function. Moving default strategy contents into ee.kicad.functions. --- src/ee/tools/part_apply_function.py | 67 +++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/ee/tools/part_apply_function.py (limited to 'src/ee/tools/part_apply_function.py') 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) -- cgit v1.2.3