Skip to content

Commit 837a481

Browse files
committed
[odml] Quick and simple odml-validation script
1 parent a612bd8 commit 837a481

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

scripts/odml-validate

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
import os
3+
import sys
4+
import odml
5+
from odml.tools.parser_utils import InvalidVersionException, ParserException
6+
7+
8+
def val(fname):
9+
doc = odml.load(fname)
10+
res = odml.validation.Validation(doc)
11+
return res
12+
13+
14+
def errtostring(error):
15+
return f"[{error.rank}] {error.path}: {error.msg}"
16+
17+
18+
if __name__ == "__main__":
19+
if len(sys.argv) < 2:
20+
sys.exit("Please provide the path to at least one file to validate")
21+
22+
filenames = sys.argv[1:]
23+
fileerrors = dict()
24+
for fname in filenames:
25+
if (os.path.exists(fname) and
26+
(os.path.isfile(fname) or os.path.islink(fname))):
27+
print(f"Validating {fname}...", flush=True, end=" ")
28+
try:
29+
v = val(fname)
30+
msgs = [errtostring(err) for err in v.errors]
31+
except InvalidVersionException as ve:
32+
msgs = [f"[error] Unsupported file format version: {ve}"]
33+
except ParserException as pe:
34+
msgs = [f"[fatal] Invalid odML file: {pe}"]
35+
fileerrors[fname] = msgs
36+
print("done")
37+
else:
38+
print(f"{fname} is not a file. Skipping validation.")
39+
40+
print(f"Completed validation of {len(filenames)} files")
41+
42+
print("=== RESULTS ===")
43+
for fname, errors in fileerrors.items():
44+
if len(errors):
45+
print(f":: {fname}: {len(errors)} issues found")
46+
for err in errors:
47+
print(f" {err}")
48+
else:
49+
print(f":: {fname} successfully validated "
50+
"with no warnings or errors")

0 commit comments

Comments
 (0)