import argparse import configparser import uuid from pathlib import Path from typing import List import ee.tools from ee.project import Project 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") cfg["kicad-project"]["uuid"] = str(uuid.uuid4()) 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) cfg["kicad-project"]["functions"] = "ee.kicad.functions.default" cfg["kicad-project"]["function-arguments"] = "" else: print("Found more than one kicad project file.") if args.kicad_bom_strategy: cfg["kicad-project"]["strategy"] = args.kicad_bom_strategy def init_digikey(project: Project): project.cfg.add_section("supplier:digikey") project.cfg["supplier:digikey"]["function"] = "ee.digikey.functions.default" 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_digikey(project) init_seeed_opl(project) if args.create_bom_strategy: project.cfg.add_section("create-bom") project.cfg["create-bom"]["strategy"] = args.create_bom_strategy print("Saving project. Now run 'ee ninja' to generate Ninja build file") project.save() parser = argparse.ArgumentParser() ee.tools.add_default_argparse_group(parser) parser.add_argument("--basedir", metavar="DIR") parser.add_argument("--kicad-bom-strategy", required=False, metavar="PY CALLABLE") parser.add_argument("--create-bom-strategy", required=False, metavar="PY CALLABLE") args = parser.parse_args() ee.tools.process_default_argparse_group(args) if not args.basedir: args.basedir = "." init(Path("."), Path(args.basedir), args)