From 52401b170d8f1c9deaa153acca76e7d6060a06df Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 25 Mar 2019 15:46:08 +0100 Subject: New command: init. Looks for kicad schematic and pcb files, creates .ee/config. ninja tool: o Use project's config to check for sch and pcb files. o Use some more conditionals in build.ninja.j2. unlockoslo: Adding demo project. --- src/ee/tools/init.py | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'src/ee/tools/init.py') diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py index a3e0472..81bdda3 100644 --- a/src/ee/tools/init.py +++ b/src/ee/tools/init.py @@ -1,10 +1,53 @@ 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() -from ee.project import init parser = argparse.ArgumentParser() +parser.add_argument("--basedir", + metavar="DIR") + args = parser.parse_args() -init(Path(".")) +if not args.basedir: + args.basedir = "." + +init(Path("."), Path(args.basedir)) -- cgit v1.2.3