aboutsummaryrefslogtreecommitdiff
path: root/src/ee/tools
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-05-21 10:17:27 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-05-21 10:17:27 +0200
commitc84c6c6bd59a03b21bd285b4f8117f566a23f8d3 (patch)
treeb327c23e01fd81e09b6a7775442ce18891612a4d /src/ee/tools
parentfa6949a45c43c08c857369389e57015b5782d604 (diff)
downloadee-python-c84c6c6bd59a03b21bd285b4f8117f566a23f8d3.tar.gz
ee-python-c84c6c6bd59a03b21bd285b4f8117f566a23f8d3.tar.bz2
ee-python-c84c6c6bd59a03b21bd285b4f8117f566a23f8d3.tar.xz
ee-python-c84c6c6bd59a03b21bd285b4f8117f566a23f8d3.zip
part-validate-parts: Even better report.
Diffstat (limited to 'src/ee/tools')
-rw-r--r--src/ee/tools/part_validate_parts.py39
1 files changed, 29 insertions, 10 deletions
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()