aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/init.py3
-rw-r--r--src/ee/tools/part_apply_function.py29
-rw-r--r--src/ee/tools/part_validate_parts.py104
-rw-r--r--src/ee/tools/templates/build.ninja.j212
4 files changed, 142 insertions, 6 deletions
diff --git a/src/ee/tools/init.py b/src/ee/tools/init.py
index 156d1b7..6d7908e 100644
--- a/src/ee/tools/init.py
+++ b/src/ee/tools/init.py
@@ -25,6 +25,9 @@ def init_kicad_project(basedir: Path, cfg, args):
if pcb_file.is_file():
cfg["kicad-project"]["pcb"] = str(pcb_file)
+
+ cfg["kicad-project"]["functions"] = "ee.kicad.functions.default"
+ cfg["kicad-project"]["function-arguments"] = ""
else:
print("Found more than one kicad project file.")
diff --git a/src/ee/tools/part_apply_function.py b/src/ee/tools/part_apply_function.py
index bece364..af51b5a 100644
--- a/src/ee/tools/part_apply_function.py
+++ b/src/ee/tools/part_apply_function.py
@@ -4,7 +4,7 @@ from pathlib import Path
from typing import List
from ee import tools, EeException
-from ee.part import Part, PartDb, load_db, save_db
+from ee.part import Part, load_db, save_db
from ee.project import Project
@@ -23,15 +23,29 @@ def load_functions(function_names):
return functions
-def work(in_path: Path, out_path: Path, report_path: Path, function_names: List[str]):
- functions = load_functions(function_names)
+def work(in_path: Path, out_path: Path, report_path: Path, function_names: List[str], arguments: List[str]):
+ factories = load_functions(function_names)
in_parts = load_db(in_path)
- parts = PartDb()
+ kwargs = {}
+ for a in arguments:
+ import re
+ k, v = re.split(":", a, maxsplit=1)
+ kwargs[k] = v
+
+ functions = [[factory[0], factory[1](**kwargs)] for factory in factories]
tools.mk_parents(report_path)
with report_path.open("w") as rpt:
+
+ if len(kwargs):
+ print("Arguments:", file=rpt)
+ print("", file=rpt)
+ for key in sorted(kwargs):
+ print(" * {}={}".format(key, kwargs[key]), file=rpt)
+ print("", file=rpt)
+
for xml in in_parts.iterparts():
part = Part(xml)
@@ -57,6 +71,11 @@ parser.add_argument("--function",
nargs="*",
metavar="FUNCTION")
+parser.add_argument("--argument",
+ required=True,
+ nargs="*",
+ metavar="ARG")
+
parser.add_argument("--execution",
default="default")
@@ -64,4 +83,4 @@ args = parser.parse_args()
project = Project.load()
report = project.report_dir / "apply-function" / (args.execution + ".rst")
-work(Path(args.in_path), Path(args.out), report, args.function)
+work(Path(args.in_path), Path(args.out), report, args.function, args.argument)
diff --git a/src/ee/tools/part_validate_parts.py b/src/ee/tools/part_validate_parts.py
new file mode 100644
index 0000000..897b0bf
--- /dev/null
+++ b/src/ee/tools/part_validate_parts.py
@@ -0,0 +1,104 @@
+import argparse
+from pathlib import Path
+
+from ee.part import Part, load_db, common_fact_types
+
+
+class Messages(object):
+ INFO = 1
+ WARNING = 2
+ ERROR = 3
+
+ def __init__(self):
+ self.messages = []
+
+ def error(self, msg):
+ self.messages.append((Messages.ERROR, msg))
+ return self
+
+ def warning(self, msg):
+ self.messages.append((Messages.WARNING, msg))
+ return self
+
+ def info(self, msg):
+ self.messages.append((Messages.INFO, msg))
+ return self
+
+ @property
+ def errors(self):
+ return [m[1] for m in self.messages if m[0] == Messages.ERROR]
+
+ @property
+ def warnings(self):
+ return [m[1] for m in self.messages if m[0] == Messages.WARNING]
+
+ @property
+ def infos(self):
+ return [m[1] for m in self.messages if m[0] == Messages.INFO]
+
+ def __len__(self):
+ return self.messages.__len__()
+
+ def append(self, messages: "Messages"):
+ self.messages.extend(messages.messages)
+
+
+def check_has_footprint(part: Part):
+ fp = part.facts.get_value(common_fact_types.footprint)
+ if fp is not None:
+ return
+
+ return Messages().warning("No footprint set")
+
+
+def validate(f, part: Part):
+ validators = [
+ check_has_footprint
+ ]
+
+ messages = Messages()
+ for validator in validators:
+ m = validator(part)
+ if m:
+ messages.append(m)
+
+ print("{}".format(part.printable_reference), file=f)
+ print("{}".format("=" * len(part.printable_reference)), file=f)
+ print("", file=f)
+
+ for msg in messages.errors:
+ print("* ERROR: {}".format(msg), file=f)
+ for msg in messages.warnings:
+ print("* WARNING: {}".format(msg), file=f)
+ for msg in messages.infos:
+ print("* INFO: {}".format(msg), file=f)
+
+ if len(messages) == 0:
+ print("No issues found", file=f)
+ print("", file=f)
+
+
+def work(in_path: Path, out_path: Path):
+ in_parts = load_db(in_path)
+
+ with out_path.open("w") as f:
+ for xml in in_parts.iterparts():
+ part = Part(xml)
+
+ validate(f, part)
+
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument("--in",
+ dest="in_path",
+ required=True,
+ metavar="PART DB")
+
+parser.add_argument("--out",
+ required=True,
+ metavar="REQUIREMENTS")
+
+args = parser.parse_args()
+
+work(Path(args.in_path), Path(args.out))
diff --git a/src/ee/tools/templates/build.ninja.j2 b/src/ee/tools/templates/build.ninja.j2
index 1f9ba35..0aaa76f 100644
--- a/src/ee/tools/templates/build.ninja.j2
+++ b/src/ee/tools/templates/build.ninja.j2
@@ -26,12 +26,15 @@ rule pn-part-search-list
command = $ee pn-part-search-list --in $in --out $out --supplier $supplier
rule part-apply-function
- command = $ee part-apply-function --in $in --out $out $functions
+ command = $ee part-apply-function --in $in --out $out $functions $arguments
rule part-find-requirements
description = part-find-requirements
command = $ee part-find-requirements --in $in --out $out
+rule part-validate-parts
+ command = $ee part-validate-parts --in $in --out $out
+
rule digikey-search-parts
description = digikey-search-parts
command = $ee digikey-search-parts --in $in --out $out
@@ -83,8 +86,15 @@ build ee/sch.xml: part-apply-function ee/kicad-sch.xml
{%- else %}
functions = --function ee.kicad.functions.default
{%- endif %}
+{%- if project.cfg["kicad-project"]["function-arguments"] %}
+ arguments = --argument {{ project.cfg["kicad-project"]["function-arguments"] }}
+{%- else %}
+ arguments = --argument ""
+{%- endif %}
{%- endif %}
+build $report_dir/part-validate-parts.rst: part-validate-parts ee/sch.xml
+
build ee/requirements.xml: part-find-requirements ee/sch.xml
{% for s in distributors %}