import os
from configparser import ConfigParser

def db_config():
    filename = os.environ.get('QWIN_CASINO_POSTGRES_INI_FILE', 'database.ini')
    
    
    curr_dir = os.path.dirname(os.path.realpath(__file__))
    
    parser = ConfigParser()
    parser.read(curr_dir + '/' + filename)
    
    db = {}
    for section in ['postgresql', 'pool']:
        if parser.has_section(section):
            params = parser.items(section)
            db[section] = {}
            
            for param in params:
                db[section][param[0]] = param[1]
    
        else:
            raise Exception('Section {0} not found in the {1} file'.format(section, filename))
            
    return db