Skip to content

Commit

Permalink
Add kcidb-validate
Browse files Browse the repository at this point in the history
Add a "kcidb-validate" tool to make it easier to validate the I/O data
without submitting it, exactly the way the submitting would.
  • Loading branch information
spbnick committed Nov 22, 2019
1 parent e355dd8 commit 0f5dc0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions kcidb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import sys
from datetime import datetime
import jsonschema
from google.cloud import bigquery
from google.api_core.exceptions import BadRequest
from kcidb import db_schema
Expand Down Expand Up @@ -212,3 +213,23 @@ def schema_main():
parser = argparse.ArgumentParser(description=description)
parser.parse_args()
json.dump(io_schema.JSON, sys.stdout, indent=4, sort_keys=True)


def validate_main():
"""Execute the kcidb-validate command-line tool"""
description = 'kcidb-validate - Validate I/O JSON data'
parser = argparse.ArgumentParser(description=description)
parser.parse_args()

try:
data = json.load(sys.stdin)
except json.decoder.JSONDecodeError as err:
print(err, sys.stderr)
return 1

try:
io_schema.validate(data)
except jsonschema.exceptions.ValidationError as err:
print(err, sys.stderr)
return 2
return 0
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"kcidb-init = kcidb:init_main",
"kcidb-cleanup = kcidb:cleanup_main",
"kcidb-schema = kcidb:schema_main",
"kcidb-validate = kcidb:validate_main",
"kcidb-submit = kcidb:submit_main",
"kcidb-query = kcidb:query_main",
]
Expand Down

0 comments on commit 0f5dc0f

Please sign in to comment.