read_dbconfig.py 807 Bytes
from configparser import ConfigParser
import os.path
 
def read_db_config(filename='base/config.ini', section='mysql'):
    filename= os.path.join(os.path.dirname(__file__), "base/config.ini")
    db = read_config(filename,section)
    return db

def read_basic_config(filename='base/config.ini', section='basics'):
    filename= os.path.join(os.path.dirname(__file__), "base/config.ini")
    config = read_config(filename,section)
    return config


def read_config(filename,section):
    parser = ConfigParser()
    parser.read(filename)
    config = {}
    if parser.has_section(section):
        items = parser.items(section)
        for item in items:
            config[item[0]] = item[1]
    else:
        raise Exception('{0} not found in the {1} file'.format(section, filename))
    return config