aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/create_order.py7
-rw-r--r--src/ee/tools/init.py27
-rw-r--r--src/ee/tools/ninja.py9
-rw-r--r--src/ee/tools/templates/build.ninja.j211
4 files changed, 36 insertions, 18 deletions
diff --git a/src/ee/tools/create_order.py b/src/ee/tools/create_order.py
index f2143a8..d740ff2 100644
--- a/src/ee/tools/create_order.py
+++ b/src/ee/tools/create_order.py
@@ -8,7 +8,7 @@ parser = argparse.ArgumentParser()
parser.add_argument("--schematic",
required=True,
- metavar="DIR")
+ metavar="PART DB")
parser.add_argument("--out",
required=True,
@@ -19,10 +19,13 @@ parser.add_argument("--part-db",
required=True,
metavar="PART DB")
+parser.add_argument("--strategy",
+ metavar="FUNC")
+
args = parser.parse_args()
project = Project.load()
part_db_dirs = [Path(part_db) for part_db in args.part_db]
fail_on_missing_parts = False
-create_order(project, Path(args.schematic), Path(args.out), part_db_dirs, fail_on_missing_parts)
+create_order(project, Path(args.schematic), Path(args.out), part_db_dirs, fail_on_missing_parts, args.strategy)
diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py
index f87c958..74a67d1 100644
--- a/src/ee/tools/init.py
+++ b/src/ee/tools/init.py
@@ -6,19 +6,19 @@ from ee.project import Project
import configparser
-def init_kicad_project(basedir: Path, cfg):
+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.add_section("kicad-project")
-
if sch_file.is_file():
print("Found KiCAD project and schematic")
cfg["kicad-project"]["sch"] = str(sch_file)
@@ -28,19 +28,26 @@ def init_kicad_project(basedir: Path, cfg):
else:
print("Found more than one kicad project file.")
+ if args.kicad_bom_strategy:
+ cfg["kicad-project"]["strategy"] = args.kicad_bom_strategy
+
def init_seeed_opl(project: Project):
import ee.supplier.seeed
ee.supplier.seeed.init_project(project)
-def init(project_dir: Path, basedir: Path):
+def init(project_dir: Path, basedir: Path, args):
cfg = configparser.ConfigParser()
project = Project(project_dir, cfg)
- init_kicad_project(basedir, cfg)
+ init_kicad_project(basedir, cfg, args)
init_seeed_opl(project)
+ if args.create_order_strategy:
+ project.cfg.add_section("create-order")
+ project.cfg["create-order"]["strategy"] = args.create_order_strategy
+
print("Saving project. Now run 'ee ninja' to generate Ninja build file")
project.save()
@@ -50,9 +57,17 @@ parser = argparse.ArgumentParser()
parser.add_argument("--basedir",
metavar="DIR")
+parser.add_argument("--kicad-bom-strategy",
+ required=False,
+ metavar="PY CALLABLE")
+
+parser.add_argument("--create-order-strategy",
+ required=False,
+ metavar="PY CALLABLE")
+
args = parser.parse_args()
if not args.basedir:
args.basedir = "."
-init(Path("."), Path(args.basedir))
+init(Path("."), Path(args.basedir), args)
diff --git a/src/ee/tools/ninja.py b/src/ee/tools/ninja.py
index a5bbe5b..c53b5da 100644
--- a/src/ee/tools/ninja.py
+++ b/src/ee/tools/ninja.py
@@ -40,7 +40,7 @@ def noext_filter(s: Union[str, Path]) -> str:
return os.path.splitext(os.path.basename(str(s)))[0]
-def generate(project: Project, kicad_bom_strategy: Optional[str]):
+def generate(project: Project):
def _create_env():
e = Environment(
loader=PackageLoader(__name__, "templates"),
@@ -72,7 +72,6 @@ def generate(project: Project, kicad_bom_strategy: Optional[str]):
params["sch"] = sch_path
params["sch_files"] = sch_files
- params["kicad_bom_strategy"] = kicad_bom_strategy
if "pcb" in kp:
params["pcb"] = Path(project.cfg["kicad-project"]["pcb"])
@@ -103,10 +102,6 @@ def generate(project: Project, kicad_bom_strategy: Optional[str]):
parser = argparse.ArgumentParser()
-parser.add_argument("--kicad-bom-strategy",
- required=False,
- metavar="PY CALLABLE")
-
args = parser.parse_args()
-generate(Project.load(), args.kicad_bom_strategy)
+generate(Project.load())
diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2
index 227b68c..6efe20b 100644
--- a/src/ee/tools/templates/build.ninja.j2
+++ b/src/ee/tools/templates/build.ninja.j2
@@ -43,7 +43,7 @@ rule element14-normalize-facts
rule create-order
description = create-order
- command = $ee create-order --schematic $schematic --part-db $part_dbs --out $out
+ command = $ee create-order --schematic $schematic --part-db $part_dbs --out $out $strategy
rule import-parts-yaml
description = import-parts-yaml $in
@@ -57,8 +57,10 @@ build {{ gerber_zip }}: kicad-gerber $pcb
{% if sch is defined -%}
build ee/sch.xml: kicad-make-bom $sch
- strategy ={{ " --strategy " + kicad_bom_strategy if kicad_bom_strategy else "" }}
-{% endif -%}
+{%- if project.cfg["kicad-project"]["strategy"] %}
+ strategy = --strategy {{ project.cfg["kicad-project"]["strategy"] }}
+{%- endif %}
+{%- endif %}
{% for d in distributors %}
# Distributor {{ d }}
build ee/{{ d }}/search-list.xml: part-create-distributor-search-list ee/sch.xml
@@ -80,6 +82,9 @@ build {{ out }}: import-parts-yaml {{ f }}
build ee/order.xml | $report_dir/order.rst: create-order ee/sch.xml {%- for p in part_dbs %} {{ p }}.xml{% endfor %}
schematic = ee/sch.xml
part_dbs ={%- for p in part_dbs %} {{ p }}.xml{% endfor %}
+{%- if project.cfg["create-order"]["strategy"] %}
+ strategy = --strategy {{ project.cfg["create-order"]["strategy"] }}
+{%- endif %}
default ee/order.xml