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)