Show More
@@ -16,7 +16,7 b' schema = os.path.join(' | |||||
16 | os.path.split(__file__)[0], "v%d" % nbformat, nbformat_schema) |
|
16 | os.path.split(__file__)[0], "v%d" % nbformat, nbformat_schema) | |
17 |
|
17 | |||
18 |
|
18 | |||
19 |
def nbvalidate(nbjson, key='/ |
|
19 | def nbvalidate(nbjson, key='/', verbose=True): | |
20 | v3schema = resolve_ref(json.load(open(schema, 'r'))) |
|
20 | v3schema = resolve_ref(json.load(open(schema, 'r'))) | |
21 | if key: |
|
21 | if key: | |
22 | v3schema = jsonpointer.resolve_pointer(v3schema, key) |
|
22 | v3schema = jsonpointer.resolve_pointer(v3schema, key) | |
@@ -62,31 +62,3 b' def convert(namein, nameout, indent=2):' | |||||
62 | x = jsonpointer.resolve_pointer(v, '/notebook') |
|
62 | x = jsonpointer.resolve_pointer(v, '/notebook') | |
63 | with open(nameout,'w') as file: |
|
63 | with open(nameout,'w') as file: | |
64 | json.dump(x,file,indent=indent) |
|
64 | json.dump(x,file,indent=indent) | |
65 |
|
||||
66 |
|
||||
67 | if __name__ == '__main__': |
|
|||
68 | parser = argparse.ArgumentParser() |
|
|||
69 | parser.add_argument('-k', '--key', |
|
|||
70 | type=str, default='/notebook', |
|
|||
71 | help='subkey to extract json schema from json file') |
|
|||
72 |
|
||||
73 | parser.add_argument("-v", "--verbose", action="store_true", |
|
|||
74 | help="increase output verbosity") |
|
|||
75 |
|
||||
76 | parser.add_argument('filename', |
|
|||
77 | type=str, |
|
|||
78 | help="file to validate", |
|
|||
79 | nargs='*', |
|
|||
80 | metavar='names') |
|
|||
81 |
|
||||
82 | args = parser.parse_args() |
|
|||
83 | for name in args.filename : |
|
|||
84 | nerror = nbvalidate(json.load(open(name,'r')), |
|
|||
85 | key=args.key, |
|
|||
86 | verbose=args.verbose) |
|
|||
87 | if nerror is 0: |
|
|||
88 | print(u"[Pass]",name) |
|
|||
89 | else : |
|
|||
90 | print(u"[ ]",name,'(%d)'%(nerror)) |
|
|||
91 | if args.verbose : |
|
|||
92 | print('==================================================') |
|
General Comments 0
You need to be logged in to leave comments.
Login now