aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools/part_validate_parts.py
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-05-20 22:46:45 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-05-20 22:53:42 +0200
commit5f3623b8dd26b37b9ea6011bf71467b2a608b5ff (patch)
tree00fdb064f9116c5bf307f8b9815500487d86482b /src/ee/tools/part_validate_parts.py
parent148ff60aa5a211292661e16ddba0f6fced85f372 (diff)
downloadee-python-5f3623b8dd26b37b9ea6011bf71467b2a608b5ff.tar.gz
ee-python-5f3623b8dd26b37b9ea6011bf71467b2a608b5ff.tar.bz2
ee-python-5f3623b8dd26b37b9ea6011bf71467b2a608b5ff.tar.xz
ee-python-5f3623b8dd26b37b9ea6011bf71467b2a608b5ff.zip
common_fact_types: Adding key for footprint.
functions: o Changing the structure of the functions, they're now factories that will be given kwargs and must return a function that processes the parts. o Adding new function to default set; 'map_footprint' that maps the KiCAD footprints to common footprints. part_validate_parts: Using only common keys.
Diffstat (limited to 'src/ee/tools/part_validate_parts.py')
-rw-r--r--src/ee/tools/part_validate_parts.py104
1 files changed, 104 insertions, 0 deletions
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))