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()

[((269, 322), 'argparse.ArgumentParser', 'argparse.ArgumentParser', ([], {'description': '"""Kinto commands"""'}), "(description='Kinto commands')\n", (292, 322), False, 'import argparse\n'), ((1148, 1177), 'pyramid.paster.bootstrap', 'bootstrap', (['"""config/kinto.ini"""'], {}), "('config/kinto.ini')\n", (1157, 1177), False, 'from pyramid.paster import bootstrap\n'), ((1288, 1310), 'pyramid.paster.bootstrap', 'bootstrap', (['config_file'], {}), '(config_file)\n', (1297, 1310), False, 'from pyramid.paster import bootstrap\n'), ((1374, 1403), 'pyramid.paster.bootstrap', 'bootstrap', (['"""config/kinto.ini"""'], {}), "('config/kinto.ini')\n", (1383, 1403), False, 'from pyramid.paster import bootstrap\n'), ((1420, 1444), 'cliquet.scripts.cliquet.init_schema', 'cliquet.init_schema', (['env'], {}), '(env)\n', (1439, 1444), False, 'from cliquet.scripts import cliquet\n'), ((1573, 1597), 'pyramid.scripts.pserve.main', 'pserve.main', (['pserve_argv'], {}), '(pserve_argv)\n', (1584, 1597), False, 'from pyramid.scripts import pserve\n')]