Created
June 3, 2016 14:12
-
-
Save jbeezley/51bb16868e878b33dae759f393403840 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
import json | |
import jsonschema | |
import requests | |
_schema = None | |
def schema(uri='https://girder.neuro.emory.edu/api/v1/annotation/schema'): | |
req = requests.get(uri) | |
if not req.ok: | |
raise Exception('Could not download schema') | |
return req.json() | |
def validate(file): | |
global _schema | |
if _schema is None: | |
_schema = schema() | |
with open(file, 'r') as f: | |
obj = json.load(f) | |
jsonschema.validate(obj, _schema) | |
def main(argv): | |
if len(sys.argv) < 2: | |
print('usage: %s file1 [file2 [...]]' % sys.argv[0]) | |
sys.exit(255) | |
haserr = 0 | |
for file in sys.argv[1:]: | |
print('\n*** Validating "%s" ***\n' % file) | |
try: | |
validate(file) | |
except jsonschema.ValidationError as err: | |
haserr += 1 | |
print('Validation failed with:') | |
print(err.message) | |
continue | |
else: | |
print('Success!\n') | |
return haserr | |
if __name__ == '__main__': | |
sys.exit(main(sys.argv)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment