<commit_before>
from banana.db import monetdb_list, postgres_list


def monetdb_db_config(host, port, passphrase, console=True):
    """
    generates a Django DATABASE configuration dict containing all
    MonetDB databases.
    """
    databases = {}
    for monetdb in monetdb_list(host, port, passphrase):
        name = monetdb['name']
        databases[name] = {
            'ENGINE': 'djonet',
            'NAME': name,
            'USER': name,
            'PASSWORD': name,
            'HOST': host,
            'PORT': port,
            'CONSOLE': console,
        }
    return databases


def postgresql_db_config(host, username, password):
    """
    generates a Django DATABASE configuration dict containing all
    postgresql databases.
    """
    databases = {}
    for name in postgres_list(host, username, password):
        databases["postgres_" + name] = {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': name,
            'USER': name,
            'PASSWORD': <PASSWORD>,
            'CONSOLE': True,
        }
    return databases


def update_config():
    """
    This will autoconfigure the django database configuration. It will
    enable all MonetDB and PostgreSQL databases reachable with the credentials
    set in the Django settings.
    """
    # we need to import this here since this module is used in the settings
    from django.conf import settings
    if not settings.DATABASE_AUTOCONFIG:
        return
    settings.DATABASES.update(monetdb_db_config(settings.MONETDB_HOST,
                                                settings.MONETDB_PORT,
                                                settings.MONETDB_PASSPHRASE))
    settings.DATABASES.update(postgresql_db_config(settings.POSTGRES_HOST,
                                                   settings.POSTGRES_USERNAME,
                                                   settings.POSTGRES_PASSWORD))<commit_msg>make config a bit more flexible<commit_after>
from banana.db import monetdb_list, postgres_list


def monetdb_db_config(host, port, passphrase, console=True):
    """
    generates a Django DATABASE configuration dict containing all
    MonetDB databases.
    """
    databases = {}
    for monetdb in monetdb_list(host, port, passphrase):
        name = monetdb['name']
        databases[name] = {
            'ENGINE': 'djonet',
            'NAME': name,
            'USER': name,
            'PASSWORD': <PASSWORD>,
            'HOST': host,
            'PORT': port,
            'CONSOLE': console,
        }
    return databases


def postgresql_db_config(host, username, password):
    """
    generates a Django DATABASE configuration dict containing all
    postgresql databases.
    """
    databases = {}
    for name in postgres_list(host, username, password):
        databases["postgres_" + name] = {
            'ENGINE': 'django.db.backends.postgresql_psycopg2',
            'NAME': name,
            'USER': name,
            'PASSWORD': <PASSWORD>,
            'CONSOLE': True,
        }
    return databases


def update_config():
    """
    This will autoconfigure the django database configuration. It will
    enable all MonetDB and PostgreSQL databases reachable with the credentials
    set in the Django settings.
    """
    # we need to import this here since this module is used in the settings
    from django.conf import settings
    if not hasattr(settings, 'DATABASE_AUTOCONFIG') \
           or not settings.DATABASE_AUTOCONFIG:
        return
    settings.DATABASES.update(monetdb_db_config(settings.MONETDB_HOST,
                                                settings.MONETDB_PORT,
                                                settings.MONETDB_PASSPHRASE))
    settings.DATABASES.update(postgresql_db_config(settings.POSTGRES_HOST,
                                                   settings.POSTGRES_USERNAME,
                                                   settings.POSTGRES_PASSWORD))
{'fraction_non_alphanumeric': 0.08201257861635221, 'fraction_numerical': 0.0005031446540880503, 'mean_word_length': 1.9343173431734317, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '909309', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1041, 'n_words': 280}