diff options
Diffstat (limited to 'src/ee/tools')
-rw-r--r-- | src/ee/tools/init.py | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py index 3f8d2b1..9b3bcf4 100644 --- a/src/ee/tools/init.py +++ b/src/ee/tools/init.py @@ -1,5 +1,4 @@ import argparse -import configparser import uuid from pathlib import Path from typing import List @@ -8,41 +7,41 @@ import ee.tools from ee.project import Project -def init_kicad_project(basedir: Path, cfg, args): +def init_kicad_project(basedir: Path, project: Project, 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") + cfg = project.get_or_create_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()) + cfg["uuid"] = cfg.get("uuid", str(uuid.uuid4())) if sch_file.is_file(): print("Found KiCAD project and schematic") - cfg["kicad-project"]["sch"] = str(sch_file) + cfg["sch"] = str(sch_file) if pcb_file.is_file(): - cfg["kicad-project"]["pcb"] = str(pcb_file) + cfg["pcb"] = str(pcb_file) - cfg["kicad-project"]["functions"] = "ee.kicad.functions.default" - cfg["kicad-project"]["function-arguments"] = "" + cfg["functions"] = cfg.get("functions", "ee.kicad.functions.default") + cfg["function-arguments"] = cfg.get("function-arguments", "ee.kicad.functions.default") else: print("Found more than one kicad project file.") if args.kicad_bom_strategy: - cfg["kicad-project"]["strategy"] = args.kicad_bom_strategy + cfg["strategy"] = args.kicad_bom_strategy def init_digikey(project: Project): - project.cfg.add_section("supplier:digikey") + supplier = project.get_or_create_section("supplier:digikey") - project.cfg["supplier:digikey"]["function"] = "ee.digikey.functions.default" + supplier["function"] = supplier.get("function", "ee.digikey.functions.default") def init_seeed_opl(project: Project): @@ -51,16 +50,15 @@ def init_seeed_opl(project: Project): def init(project_dir: Path, basedir: Path, args): - cfg = configparser.ConfigParser() - project = Project(project_dir, cfg) + project = Project.load(project_dir) - init_kicad_project(basedir, cfg, args) + init_kicad_project(basedir, project, 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 + create_bom = project.get_or_create_section("create-bom") + create_bom["strategy"] = args.create_bom_strategy print("Saving project. Now run 'ee ninja' to generate Ninja build file") project.save() |