def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING, argv=None):
    # Use sys.argv if we've not passed in a custom argv
    if argv is None:
        argv = sys.argv

    # Parse the command-line arguments. optparse handles the dirty work.
    parser = DjangoOptionParser(usage=get_usage(action_mapping), version=get_version())
    parser.add_option('--settings',
        help='Python path to settings module, e.g. "myproject.settings.main". If this isn\'t provided, the DJANGO_SETTINGS_MODULE environment variable will be used.')
    parser.add_option('--pythonpath',
        help='Lets you manually add a directory the Python path, e.g. "/home/djangoprojects/myproject".')
    parser.add_option('--plain', action='store_true', dest='plain',
        help='Tells Django to use plain Python, not IPython, for "shell" command.')
    parser.add_option('--noinput', action='store_false', dest='interactive', default=True,
        help='Tells Django to NOT prompt the user for input of any kind.')
    parser.add_option('--noreload', action='store_false', dest='use_reloader', default=True,
        help='Tells Django to NOT use the auto-reloader when running the development server.')
    parser.add_option('--format', default='json', dest='format',
        help='Specifies the output serialization format for fixtures')    
    parser.add_option('--indent', default=None, dest='indent',
        type='int', help='Specifies the indent level to use when pretty-printing output')
    parser.add_option('--verbosity', action='store', dest='verbosity', default='1',
        type='choice', choices=['0', '1', '2'],
        help='Verbosity level; 0=minimal output, 1=normal output, 2=all output'),
    parser.add_option('--adminmedia', dest='admin_media_path', default='', help='Specifies the directory from which to serve admin media for runserver.'),

    options, args = parser.parse_args(argv[1:])

    # Take care of options.
    if options.settings:
        os.environ['DJANGO_SETTINGS_MODULE'] = options.settings
    if options.pythonpath:
        sys.path.insert(0, options.pythonpath)

    # Run the appropriate action. Unfortunately, optparse can't handle
    # positional arguments, so this has to parse/validate them.
    try:
        action = args[0]
    except IndexError:
        parser.print_usage_and_exit()
    if not action_mapping.has_key(action):
        print_error("Your action, %r, was invalid." % action, argv[0])

    # Switch to English, because django-admin.py creates database content
    # like permissions, and those shouldn't contain any translations.
    # But only do this if we should have a working settings file.
    if action not in ('startproject', 'startapp'):
        from django.utils import translation
        translation.activate('en-us')

    if action == 'shell':
        action_mapping[action](options.plain is True)
    elif action in ('validate', 'diffsettings', 'dbshell'):
        action_mapping[action]()
    elif action in ('flush', 'syncdb'):
        action_mapping[action](int(options.verbosity), options.interactive)
    elif action == 'inspectdb':
        try:
            for line in action_mapping[action]():
                print line
        except NotImplementedError:
            sys.stderr.write(style.ERROR("Error: %r isn't supported for the currently selected database backend.\n" % action))
            sys.exit(1)
    elif action == 'createcachetable':
        try:
            action_mapping[action](args[1])
        except IndexError:
            parser.print_usage_and_exit()
    elif action in ('test', 'loaddata'):
        try:
            action_mapping[action](args[1:], int(options.verbosity))
        except IndexError:
            parser.print_usage_and_exit()
    elif action == 'dumpdata':
        try:
            print action_mapping[action](args[1:], options.format, options.indent)
        except IndexError:
            parser.print_usage_and_exit()
    elif action in ('startapp', 'startproject'):
        try:
            name = args[1]
        except IndexError:
            parser.print_usage_and_exit()
        action_mapping[action](name, os.getcwd())
    elif action == 'runserver':
        if len(args) < 2:
            addr = ''
            port = '8000'
        else:
            try:
                addr, port = args[1].split(':')
            except ValueError:
                addr, port = '', args[1]
        action_mapping[action](addr, port, options.use_reloader, options.admin_media_path)
    elif action == 'runfcgi':
        action_mapping[action](args[1:])
    elif action == 'sqlinitialdata':
        print action_mapping[action](args[1:])
    elif action == 'sqlflush':
        print '\n'.join(action_mapping[action]())
    else:
        from django.db import models
        validate(silent_success=True)
        try:
            mod_list = [models.get_app(app_label) for app_label in args[1:]]
        except ImportError, e:
            sys.stderr.write(style.ERROR("Error: %s. Are you sure your INSTALLED_APPS setting is correct?\n" % e))
            sys.exit(1)
        if not mod_list:
            parser.print_usage_and_exit()
        if action not in NO_SQL_TRANSACTION:
            print style.SQL_KEYWORD("BEGIN;")
        for mod in mod_list:
            if action == 'reset':
                output = action_mapping[action](mod, options.interactive)
            else:
                output = action_mapping[action](mod)
            if output:
                print '\n'.join(output)
        if action not in NO_SQL_TRANSACTION:
            print style.SQL_KEYWORD("COMMIT;")
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-0.96/django/core/management.py/execute_from_command_line/original