From 8d17fb5bc4b0dae0758e01a44d77d87acf2e686a Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Thu, 14 Mar 2019 06:27:16 +0100 Subject: o Adding module for searching on element14. o Starting on functionality create orders. Very WIP. o Adding a concept of an "ee project". Can load a gitconfig-like config file. o Adding a tool to import a yaml file into a part xml file. --- src/ee/tools/ninja.py | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'src/ee/tools/ninja.py') diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py index cc090a0..ed8e91a 100644 --- a/src/ee/tools/ninja.py +++ b/src/ee/tools/ninja.py @@ -1,4 +1,5 @@ import argparse +import os.path import sys from pathlib import Path from typing import List, Union, Optional @@ -8,7 +9,10 @@ from jinja2 import Environment, PackageLoader, select_autoescape from ee.kicad import read_schematics -def ninja_path_filter(s: Union[str, List[str]]) -> str: +def ninja_path_filter(s: Union[Path, str, List[str]]) -> str: + if isinstance(s, Path): + s = str(s) + if isinstance(s, str): return s. \ replace("$", "$$"). \ @@ -23,8 +27,16 @@ def ninja_path_filter(s: Union[str, List[str]]) -> str: raise Exception("Unsupported argument type: {}".format(type(s))) -def parent_dir_filter(s: str) -> str: - return str(Path(s).parent) +def parent_dir_filter(s: str) -> Path: + return Path(s).parent + + +def basename_filter(s: Union[str, Path]) -> str: + return os.path.basename(str(s)) + + +def noext_filter(s: Union[str, Path]) -> str: + return os.path.splitext(os.path.basename(str(s)))[0] def generate(sch_path: Path, kicad_bom_strategy: Optional[str]): @@ -36,6 +48,8 @@ def generate(sch_path: Path, kicad_bom_strategy: Optional[str]): ) e.filters["ninja_path"] = ninja_path_filter e.filters["parent_dir"] = parent_dir_filter + e.filters["basename"] = basename_filter + e.filters["noext"] = noext_filter return e gerber_zip = "prod/gerber.zip" @@ -44,20 +58,30 @@ def generate(sch_path: Path, kicad_bom_strategy: Optional[str]): sch_files = sorted([s.path for s in sch.schematics]) - params = {} - import os.path - params["ee"] = "{} -m ee".format(os.path.relpath(sys.executable, Path("."))) - params["sch"] = sch_path - params["sch_files"] = sch_files - - params["kicad_bom_strategy"] = kicad_bom_strategy + part_dbs = [] + params = { + "ee": "{} -m ee".format(os.path.relpath(sys.executable, Path("."))), "sch": sch_path, + "sch_files": sch_files, "kicad_bom_strategy": kicad_bom_strategy, + "pcb": str(sch_path).replace(".sch", ".kicad_pcb"), + "part_dbs": part_dbs, + } - params["pcb"] = str(sch_path).replace(".sch", ".kicad_pcb") + # TODO: read from config + distributors = ["digikey"] + params["distributors"] = distributors if gerber_zip is not None: params["gerber_zip"] = gerber_zip - build_ninja = Path("build.ninja") + build_ninja = sch_path.parent / "build.ninja" + + ee_dir = sch_path.parent / "ee" + parts_yaml_files = [path for path in ee_dir.iterdir() if str(path).endswith("-parts.yaml")] + params["parts_yaml_files"] = parts_yaml_files + + # Local part databases first + part_dbs.extend([parent_dir_filter(p) / noext_filter(p) for p in parts_yaml_files]) + part_dbs.extend([Path("ee") / d / "normalized" for d in distributors]) with build_ninja.open("w") as f: env = _create_env() @@ -77,4 +101,4 @@ parser.add_argument("--kicad-bom-strategy", args = parser.parse_args() -generate(args.sch, args.kicad_bom_strategy) +generate(Path(args.sch), args.kicad_bom_strategy) -- cgit v1.2.3