From c84c6c6bd59a03b21bd285b4f8117f566a23f8d3 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Tue, 21 May 2019 10:17:27 +0200 Subject: part-validate-parts: Even better report. --- src/ee/tools/part_validate_parts.py | 39 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/ee/tools/part_validate_parts.py b/src/ee/tools/part_validate_parts.py index 897b0bf..7028694 100644 --- a/src/ee/tools/part_validate_parts.py +++ b/src/ee/tools/part_validate_parts.py @@ -1,4 +1,5 @@ import argparse +from itertools import groupby from pathlib import Path from ee.part import Part, load_db, common_fact_types @@ -9,32 +10,33 @@ class Messages(object): WARNING = 2 ERROR = 3 - def __init__(self): + def __init__(self, part): + self.part = part self.messages = [] def error(self, msg): - self.messages.append((Messages.ERROR, msg)) + self.messages.append((self.part, Messages.ERROR, msg)) return self def warning(self, msg): - self.messages.append((Messages.WARNING, msg)) + self.messages.append((self.part, Messages.WARNING, msg)) return self def info(self, msg): - self.messages.append((Messages.INFO, msg)) + self.messages.append((self.part, Messages.INFO, msg)) return self @property def errors(self): - return [m[1] for m in self.messages if m[0] == Messages.ERROR] + return [m[2] for m in self.messages if m[1] == Messages.ERROR] @property def warnings(self): - return [m[1] for m in self.messages if m[0] == Messages.WARNING] + return [m[2] for m in self.messages if m[1] == Messages.WARNING] @property def infos(self): - return [m[1] for m in self.messages if m[0] == Messages.INFO] + return [m[2] for m in self.messages if m[1] == Messages.INFO] def __len__(self): return self.messages.__len__() @@ -48,7 +50,7 @@ def check_has_footprint(part: Part): if fp is not None: return - return Messages().warning("No footprint set") + return Messages(part).warning("No footprint") def validate(f, part: Part): @@ -56,7 +58,7 @@ def validate(f, part: Part): check_has_footprint ] - messages = Messages() + messages = Messages(part) for validator in validators: m = validator(part) if m: @@ -77,15 +79,32 @@ def validate(f, part: Part): print("No issues found", file=f) print("", file=f) + return messages + def work(in_path: Path, out_path: Path): in_parts = load_db(in_path) with out_path.open("w") as f: + messages = Messages(None) + for xml in in_parts.iterparts(): part = Part(xml) - validate(f, part) + ms = validate(f, part) + messages.append(ms) + + print("", file=f) + print("Message index", file=f) + print("=============", file=f) + print("", file=f) + for message, messages_ in groupby(messages.messages, lambda m: m[2]): + messages = list(messages_) + print(message, file=f) + print("{}".format("-" * len(message)), file=f) + + for m in messages: + print(" * {}".format(m[0].printable_reference), file=f) parser = argparse.ArgumentParser() -- cgit v1.2.3