import argparse from pathlib import Path from typing import List from ee.project import Project import configparser def init_kicad_project(basedir: Path, cfg, args): pro_files: List[Path] = [f for f in basedir.iterdir() if f.name.endswith(".pro")] if len(pro_files) == 0: return cfg.add_section("kicad-project") if len(pro_files) == 1: pro_file = pro_files[0] sch_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".sch") pcb_file: Path = pro_file.parent / (pro_file.name[0:-4] + ".kicad_pcb") if sch_file.is_file(): print("Found KiCAD project and schematic") cfg["kicad-project"]["sch"] = str(sch_file) if pcb_file.is_file(): cfg["kicad-project"]["pcb"] = str(pcb_file) else: print("Found more than one kicad project file.") if args.kicad_bom_strategy: cfg["kicad-project"]["strategy"] = args.kicad_bom_strategy def init_seeed_opl(project: Project): import ee.supplier.seeed ee.supplier.seeed.init_project(project) def init(project_dir: Path, basedir: Path, args): cfg = configparser.ConfigParser() project = Project(project_dir, cfg) init_kicad_project(basedir, cfg, args) init_seeed_opl(project) if args.create_order_strategy: project.cfg.add_section("create-order") project.cfg["create-order"]["strategy"] = args.create_order_strategy print("Saving project. Now run 'ee ninja' to generate Ninja build file") project.save() parser = argparse.ArgumentParser() parser.add_argument("--basedir", metavar="DIR") parser.add_argument("--kicad-bom-strategy", required=False, metavar="PY CALLABLE") parser.add_argument("--create-order-strategy", required=False, metavar="PY CALLABLE") args = parser.parse_args() if not args.basedir: args.basedir = "." init(Path("."), Path(args.basedir), args)