from __future__ import print_function
#!/usr/bin/env python
# -*- coding: utf8 -*-
import argparse
import traceback
import json
import os

from IPython.external.jsonschema import Draft3Validator, validate, ValidationError
import IPython.external.jsonpointer as jsonpointer
from IPython.utils.py3compat import iteritems


from .current import nbformat, nbformat_schema
schema = os.path.join(
    os.path.split(__file__)[0], "v%d" % nbformat, nbformat_schema)


def nbvalidate(nbjson, key='/notebook', verbose=True):
    v3schema = resolve_ref(json.load(open(schema, 'r')))
    if key:
        v3schema = jsonpointer.resolve_pointer(v3schema, key)
    errors = 0
    v = Draft3Validator(v3schema)
    for error in v.iter_errors(nbjson):
        errors = errors + 1
        if verbose:
            print(error)
    return errors


def resolve_ref(json, base=None):
    """return a json with resolved internal references

    only support local reference to the same json
    """
    if not base :
        base = json

    temp = None
    if type(json) is list:
        temp = [];
        for item in json:
            temp.append(resolve_ref(item, base=base))
    elif type(json) is dict:
        temp = {};
        for key,value in iteritems(json):
            if key == '$ref':
                return resolve_ref(jsonpointer.resolve_pointer(base,value), base=base)
            else :
                temp[key]=resolve_ref(value, base=base)
    else :
        return json
    return temp

def convert(namein, nameout, indent=2):
    """resolve the references of namein, save the result in nameout"""
    jsn = None
    with open(namein) as file :
        jsn = json.load(file)
    v = resolve_ref(jsn, base=jsn)
    x = jsonpointer.resolve_pointer(v, '/notebook')
    with open(nameout,'w') as file:
        json.dump(x,file,indent=indent)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-k', '--key',
                    type=str, default='/notebook',
                    help='subkey to extract json schema from json file')

    parser.add_argument("-v", "--verbose", action="store_true",
                    help="increase output verbosity")

    parser.add_argument('filename',
            type=str,
            help="file to validate",
            nargs='*',
            metavar='names')

    args = parser.parse_args()
    for name in args.filename :
        nerror = nbvalidate(json.load(open(name,'r')),
                            key=args.key,
                            verbose=args.verbose)
        if nerror is 0:
            print(u"[Pass]",name)
        else :
            print(u"[    ]",name,'(%d)'%(nerror))
        if args.verbose :
            print('==================================================')

@@ -482,24 +482,16 @@
 , key='/
-notebook
 ', verbo
@@ -1827,934 +1827,4 @@
 nt)%0A
-%0A%0Aif __name__ == '__main__':%0A    parser = argparse.ArgumentParser()%0A    parser.add_argument('-k', '--key',%0A                    type=str, default='/notebook',%0A                    help='subkey to extract json schema from json file')%0A%0A    parser.add_argument(%22-v%22, %22--verbose%22, action=%22store_true%22,%0A                    help=%22increase output verbosity%22)%0A%0A    parser.add_argument('filename',%0A            type=str,%0A            help=%22file to validate%22,%0A            nargs='*',%0A            metavar='names')%0A%0A    args = parser.parse_args()%0A    for name in args.filename :%0A        nerror = nbvalidate(json.load(open(name,'r')),%0A                            key=args.key,%0A                            verbose=args.verbose)%0A        if nerror is 0:%0A            print(u%22%5BPass%5D%22,name)%0A        else :%0A            print(u%22%5B    %5D%22,name,'(%25d)'%25(nerror))%0A        if args.verbose :%0A            print('==================================================')%0A

Remove if __name__ == '__main__' code from validator