Skip to content

Commit 0f5dc0f

Browse files
committed
Add kcidb-validate
Add a "kcidb-validate" tool to make it easier to validate the I/O data without submitting it, exactly the way the submitting would.
1 parent e355dd8 commit 0f5dc0f

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

kcidb/__init__.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import json
66
import sys
77
from datetime import datetime
8+
import jsonschema
89
from google.cloud import bigquery
910
from google.api_core.exceptions import BadRequest
1011
from kcidb import db_schema
@@ -212,3 +213,23 @@ def schema_main():
212213
parser = argparse.ArgumentParser(description=description)
213214
parser.parse_args()
214215
json.dump(io_schema.JSON, sys.stdout, indent=4, sort_keys=True)
216+
217+
218+
def validate_main():
219+
"""Execute the kcidb-validate command-line tool"""
220+
description = 'kcidb-validate - Validate I/O JSON data'
221+
parser = argparse.ArgumentParser(description=description)
222+
parser.parse_args()
223+
224+
try:
225+
data = json.load(sys.stdin)
226+
except json.decoder.JSONDecodeError as err:
227+
print(err, sys.stderr)
228+
return 1
229+
230+
try:
231+
io_schema.validate(data)
232+
except jsonschema.exceptions.ValidationError as err:
233+
print(err, sys.stderr)
234+
return 2
235+
return 0

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"kcidb-init = kcidb:init_main",
5353
"kcidb-cleanup = kcidb:cleanup_main",
5454
"kcidb-schema = kcidb:schema_main",
55+
"kcidb-validate = kcidb:validate_main",
5556
"kcidb-submit = kcidb:submit_main",
5657
"kcidb-query = kcidb:query_main",
5758
]

0 commit comments

Comments
 (0)