import argparse from pathlib import Path from typing import List from ee.project import Project import configparser def init_kicad_project(basedir: Path, cfg): print("basedir={}".format(basedir)) pro_files: List[Path] = [f for f in basedir.iterdir() if f.name.endswith(".pro")] if len(pro_files) == 0: return 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.add_section("kicad-project") 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.") def init(project_dir: Path, basedir: Path): cfg = configparser.ConfigParser() project = Project(project_dir, cfg) init_kicad_project(basedir, cfg) print("Saving project. Now run 'ee ninja' to generate Ninja build file") project.save() parser = argparse.ArgumentParser() parser.add_argument("--basedir", metavar="DIR") args = parser.parse_args() if not args.basedir: args.basedir = "." init(Path("."), Path(args.basedir))