<commit_before>'''
based on environment variables make a config file for build out
'''
import os


BASE = '''[buildout]
extends = buildout.cfg

[production-ini]
file_upload_bucket = elasticbeanstalk-{env_name}-files
blob_bucket = elasticbeanstalk-{env_name}-blobs
system_bucket = elasticbeanstalk-{env_name}-system
region_search_instance = 172.31.49.128:9872
elasticsearch_instance = 172.31.49.128:9872
elasticsearch_index = {env_name}
sqlalchemy_url = {dbconn}

create_tables = true
load_test_data = encoded.loadxl:{load_function}
'''

def dbconn_from_env():
    prfx = "RDS"
    if prfx:
        db = os.environ[prfx + '_DB_NAME']
        user = os.environ[prfx + '_USERNAME']
        pwd =  os.environ[prfx + '_PASSWORD']
        host = os.environ[prfx + '_HOSTNAME']
        port = os.environ[prfx + '_PORT']
        return "postgresql://%s:%s@%s:%s/%s" % (user, pwd, host, port, db)
    return "postgresql://abh:def@local-host:123/ebd"

def build_cfg_file():
    data = {}
    data['dbconn'] = dbconn_from_env()
    data['env_name'] = os.environ.get("ENV_NAME", "")
    data['load_function'] = 'load_test_data'
    # this is temporary while we have environments switched, change back later
    # if 'prod' in data['env_name'].lower():
    if data['env_name'].lower() in ['4dn-web-dev', 'fourfront-webdev']:
        data['load_function'] = 'load_prod_data'

    file_dir, _ = os.path.split(os.path.abspath(__file__))
    filename = os.path.join(file_dir, '..','beanstalk.cfg')
    print (filename)

    with open(filename, 'w') as bs_ini:
        bs_ini.write(BASE.format(**data))


if __name__ == "__main__":
    build_cfg_file()
<commit_msg>generate appropriate connection for es5<commit_after>'''
based on environment variables make a config file for build out
'''
import os


BASE = '''[buildout]
extends = buildout.cfg

[production-ini]
file_upload_bucket = elasticbeanstalk-{env_name}-files
blob_bucket = elasticbeanstalk-{env_name}-blobs
system_bucket = elasticbeanstalk-{env_name}-system
region_search_instance = {es_server}
elasticsearch_instance = {es_server}
elasticsearch_index = {env_name}
sqlalchemy_url = {dbconn}

create_tables = true
load_test_data = encoded.loadxl:{load_function}
'''


def dbconn_from_env():
    prfx = "RDS"
    if prfx:
        db = os.environ[prfx + '_DB_NAME']
        user = os.environ[prfx + '_USERNAME']
        pwd = os.environ[prfx + '_PASSWORD']
        host = os.environ[prfx + '_HOSTNAME']
        port = os.environ[prfx + '_PORT']
        return "postgresql://%s:%s@%s:%s/%s" % (user, pwd, host, port, db)
    return "postgresql://abh:def@local-host:123/ebd"


def build_cfg_file():
    data = {}
    data['dbconn'] = dbconn_from_env()
    data['env_name'] = os.environ.get("ENV_NAME", "")
    data['load_function'] = 'load_test_data'
    # this is temporary while we have environments switched, change back later
    # if 'prod' in data['env_name'].lower():
    if data['env_name'].lower() in ['4dn-web-dev', 'fourfront-webdev']:
        data['es_server'] = '172.31.49.128:9872'
        data['load_function'] = 'load_prod_data'
    elif data['env_name'].lower() == 'fourfront-webprod':
        data['es_server'] = '172.31.16.84:9872'

    file_dir, _ = os.path.split(os.path.abspath(__file__))
    filename = os.path.join(file_dir, '..', 'beanstalk.cfg')
    print (filename)

    with open(filename, 'w') as bs_ini:
        bs_ini.write(BASE.format(**data))


if __name__ == "__main__":
    build_cfg_file()

{'fraction_non_alphanumeric': 0.1544903263066705, 'fraction_numerical': 0.018481085763788624, 'mean_word_length': 3.9134751773049645, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '947887', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1218, 'n_words': 241}