Source

jsonwidget-python / jwc

Full commit
#!/usr/bin/python
""" Utility functions for jsonwidget"""
import optparse
import sys

import jsonwidget.commands

from jsonwidget.jsontypes import schemaformat

if __name__ == "__main__":
    '''urwid-based image metadata editor'''
    usage = """\
usage: %prog command filename
  Valid commands:
    editserver:    launch a web server to edit a json file from a browser
    json2plist:    convert a json file to an XML-formatted plist
    json2yaml:     convert a json file to yaml with comments pulled from schema
    plist2json:    convert a XML-formatted plist file to json
    schemagen:     create a schema from an example json file
    upgradeschema: create a version 2 schema from a version 1 schema
    validate:      validate a schema
    yaml2json:     convert a yaml file to json\
"""
    cmdparser = optparse.OptionParser(usage)
    cmdparser.disable_interspersed_args()
    (options, args) = cmdparser.parse_args()

    if len(args)<1:
        cmdparser.error("no command given")
    elif args[0] == 'upgradeschema':
        jsonwidget.commands.upgradeschema(args)
    elif args[0] == 'schemagen':
        jsonwidget.commands.schemagen(args)
    elif args[0] == 'json2yaml':
        jsonwidget.commands.json2yaml(args)
    elif args[0] == 'yaml2json':
        jsonwidget.commands.yaml2json(args)
    elif args[0] == 'json2plist':
        jsonwidget.commands.json2plist(args)
    elif args[0] == 'json2xmlrpc':
        jsonwidget.commands.json2xmlrpc(args)
    elif args[0] == 'plist2json':
        jsonwidget.commands.plist2json(args)
    elif args[0] == 'validate':
        jsonwidget.commands.validate(args)
    elif args[0] == 'editserver':
        jsonwidget.commands.editserver(args)
    else:
        cmdparser.error(args[0] + ' is not a valid command.')