def setup_environment(path):
    IDENTIFIERS = get_config_identifiers(path)
    CONFIG_IDENTIFIER = os.environ.get('CONFIG_IDENTIFIER', '')

    # If we are trying to use runserver, then look for existing configuration so that auto reload does not keep propmpting for the configuration file.
    if len(sys.argv) >= 2 and sys.argv[1] in ('runserver', 'runserver_plus',):
        if 'CONFIG_IDENTIFIER' in os.environ and CONFIG_IDENTIFIER in [name for id, name in IDENTIFIERS]:
            bootstrap(path)
            return

    IDENTIFIERS_LOOKUP = dict(IDENTIFIERS)
    IDENTIFIERS_REVERSE_LOOKUP = dict([[ name, id ] for id, name in IDENTIFIERS ])

    CONFIG_IDENTIFIER_ID = IDENTIFIERS_REVERSE_LOOKUP.get(CONFIG_IDENTIFIER, '')
    CONFIG_IDENTIFIER_INTERACTIVE = os.environ.get('CONFIG_IDENTIFIER_INTERACTIVE', 'True')

    if CONFIG_IDENTIFIER and CONFIG_IDENTIFIER_INTERACTIVE == 'False':
        print "WARNING: Forced to run environment with %s configuration." % CONFIG_IDENTIFIER.upper()
        return bootstrap(path)

    while True:
        print "Please select your config identifier."
        for id, name in IDENTIFIERS:
            print (id, name) % "   %s) %s"

        try:
            selection = raw_input("What config identifier would you like to use? [%s] " % CONFIG_IDENTIFIER_ID)
        except:
            # Capture if they hard escape during the getpass prompt. Clear the newline, and exit.
            print ''
            sys.exit(0)

        selection = selection.isdigit() and int(selection) or (selection and selection or CONFIG_IDENTIFIER_ID)

        if selection and IDENTIFIERS_LOOKUP.has_key(selection):
            identifier = dict(IDENTIFIERS).get(int(selection))

            # We need to load up the selected settings environment to see if we need to double check for security purposes.
            # If the database_host is not empty (not a local database) then we need to confirm that the user REALLY wants
            # to run the command on a potentially production database.
            settings_path = find_settings_path(path)


            # Set the config identifier to the selected one, so that the correct configuration gets loaded up.
            os.environ['CONFIG_IDENTIFIER'] = identifier
            os.putenv('CONFIG_IDENTIFIER', identifier)

            # Import the settings file into local scope.
            settings = imp.load_source('settings', os.path.join(settings_path, 'settings.py'))

            # Reset the config identifier and system path to what they were before.
            os.putenv('CONFIG_IDENTIFIER', CONFIG_IDENTIFIER)
            os.environ['CONFIG_IDENTIFIER'] = CONFIG_IDENTIFIER

            # If the database host for the selected configuration is not empty (not a local database). Prompt for password.
            if getattr(settings, 'ENABLE_PASSWORD', False) and getattr(settings, 'PASSWORD_DIGEST', ''):
                try:
                    password = getpass.getpass('Please enter the password to load <%s>: ' % identifier)
                except:
                    # Capture if they hard escape during the getpass prompt. Clear the newline, and exit.
                    print ''
                    sys.exit(0)
                else:
                    if hashlib.md5(password).hexdigest() != settings.PASSWORD_DIGEST:
                        print 'Invalid password.'
                        continue


            CONFIG_IDENTIFIER = identifier
            break

    # Update the current config identifier.
    os.environ['CONFIG_IDENTIFIER'] = CONFIG_IDENTIFIER
    os.putenv('CONFIG_IDENTIFIER', CONFIG_IDENTIFIER)

    # Now that we have setup our identifier, initialize our django project.
    bootstrap(path)
dataset/ETHPy150Open tarequeh/django-config/djangoconfig/deployment.py/setup_environment/swapped operands of `%`