import argparse
import sys
from cliquet.scripts import cliquet
from pyramid.scripts import pserve
from pyramid.paster import bootstrap


def main(args=None):
        """The main routine."""
        if args is None:
                args = sys.argv[1:]

        parser = argparse.ArgumentParser(description="Kinto commands")
        subparsers = parser.add_subparsers(title='subcommands',
                                           description='valid subcommands',
                                           help='init/start/migrate')

        parser_init = subparsers.add_parser('init')
        parser_init.set_defaults(which='init')
        parser_init.add_argument('--config_file', required=False,
                                 help='Config file may be passed as argument')

        parser_migrate = subparsers.add_parser('migrate')
        parser_migrate.set_defaults(which='migrate')

        parser_start = subparsers.add_parser('start')
        parser_start.set_defaults(which='start')

        args = vars(parser.parse_args())

        if args['which'] == 'init':
                if(args['config_file'] is None):
                    env = bootstrap('config/kinto.ini')
                else:
                    config_file = format(args['config_file'])
                    env = bootstrap(config_file)
        elif args['which'] == 'migrate':
                env = bootstrap('config/kinto.ini')
                cliquet.init_schema(env)
        elif args['which'] == 'start':
                pserve_argv = ['pserve', 'config/kinto.ini', '--reload']
                pserve.main(pserve_argv)


if __name__ == "__main__":
        main()

[((13, 17, 13, 70), 'argparse.ArgumentParser', 'argparse.ArgumentParser', (), '', False, 'import argparse\n'), ((33, 26, 33, 55), 'pyramid.paster.bootstrap', 'bootstrap', ({(33, 36, 33, 54): '"""config/kinto.ini"""'}, {}), "('config/kinto.ini')", False, 'from pyramid.paster import bootstrap\n'), ((36, 26, 36, 48), 'pyramid.paster.bootstrap', 'bootstrap', ({(36, 36, 36, 47): 'config_file'}, {}), '(config_file)', False, 'from pyramid.paster import bootstrap\n'), ((38, 22, 38, 51), 'pyramid.paster.bootstrap', 'bootstrap', ({(38, 32, 38, 50): '"""config/kinto.ini"""'}, {}), "('config/kinto.ini')", False, 'from pyramid.paster import bootstrap\n'), ((39, 16, 39, 40), 'cliquet.scripts.cliquet.init_schema', 'cliquet.init_schema', ({(39, 36, 39, 39): 'env'}, {}), '(env)', False, 'from cliquet.scripts import cliquet\n'), ((42, 16, 42, 40), 'pyramid.scripts.pserve.main', 'pserve.main', ({(42, 28, 42, 39): 'pserve_argv'}, {}), '(pserve_argv)', False, 'from pyramid.scripts import pserve\n')]