Esempio n. 1
0
def editserver(args):
    import json
    import sys
    from jsonwidget.server.wsgieditserver import start_server

    usage = """\
Launch a web server which serves a Javascript-based JSON editor for a single \
file.
usage: %prog editserver [options] jsonfile\
"""

    schemafile = jsonwidget.find_system_schema("openschema.json")
    subparser = optparse.OptionParser(usage=usage)
    schemahelp = "schema format version to use.  Default: %s" % schemafile
    subparser.add_option("-s",
                         "--schema",
                         dest="schema",
                         type="str",
                         default=schemafile,
                         help=schemahelp)
    (options, subargs) = subparser.parse_args(args[1:])

    if len(subargs) == 1:
        start_server(jsonfile=subargs[0], schemafile=options.schema)
    elif len(subargs) < 1:
        subparser.error("jsonfile required")
    else:
        subparser.error("only one file at a time")
Esempio n. 2
0
def validate(args):
    import json
    import sys

    usage = """\
Validate a JSON file against a schema.
usage: %prog validate [options] jsonfile\
"""
    schemafile = jsonwidget.find_system_schema("openschema.json")
    subparser = optparse.OptionParser(usage=usage)
    schemahelp = "schema format version to use.  Default: %s" % schemafile
    subparser.add_option("-s",
                         "--schema",
                         dest="schema",
                         type="str",
                         default=schemafile,
                         help=schemahelp)
    (options, subargs) = subparser.parse_args(args[1:])
    if len(subargs) == 1:
        try:
            jsonwidget.jsonnode.JsonNode(filename=subargs[0],
                                         schemafile=options.schema)
            print "Valid file!  " + subargs[0] + \
                " validates against " + options.schema
        except jsonwidget.jsonnode.JsonNodeError as inst:
            print str(inst)
            sys.exit(1)
    elif len(subargs) < 1:
        subparser.error("jsonfile required")
    else:
        subparser.error("only one file at a time")
Esempio n. 3
0
def jsonaddress():
    '''urwid-based JSON address book editor'''
    usage = "usage: %prog [options] arg"
    parser = optparse.OptionParser(usage)
    (options, args) = parser.parse_args()

    if len(args) > 1:
        parser.error("Too many arguments." +
                     "  Just one adddressbook file at a time, please.")
    if len(args) == 1:
        addressbook = args[0]
    else:
        addressbook = None

    defschema = jsonwidget.find_system_schema("addressbookschema.json")
    progname = "jsonaddress " + jsonwidget.__version__
    try:
        jsonwidget.run_editor(addressbook, schemafile=defschema,
                              program_name=progname)
    except JsonNodeError as inst:
        sys.stderr.writelines(parser.get_prog_name() + " error:\n")
        sys.stderr.writelines(str(inst) + "\n\n")
        sys.exit(2)
Esempio n. 4
0
def jsonaddress():
    '''urwid-based JSON address book editor'''
    usage = "usage: %prog [options] arg"
    parser = optparse.OptionParser(usage)
    (options, args) = parser.parse_args()

    if len(args) > 1:
        parser.error("Too many arguments." +
                     "  Just one adddressbook file at a time, please.")
    if len(args) == 1:
        addressbook = args[0]
    else:
        addressbook = None

    defschema = jsonwidget.find_system_schema("addressbookschema.json")
    progname = "jsonaddress " + jsonwidget.__version__
    try:
        jsonwidget.run_editor(addressbook,
                              schemafile=defschema,
                              program_name=progname)
    except JsonNodeError as inst:
        sys.stderr.writelines(parser.get_prog_name() + " error:\n")
        sys.stderr.writelines(str(inst) + "\n\n")
        sys.exit(2)