#!/usr/bin/env python
from configparser import ConfigParser
 
 
def config(filename='db.config', section='postgis'):
    # create a config parser
    parser = ConfigParser()
    # read database configuration file
    parser.read(filename)
 
    # parse postgis section
    postgis_db = {}
    if parser.has_section(section):
        params = parser.items(section)
        for param in params:
            postgis_db[param[0]] = param[1]
    else:
        raise Exception('Section {0} not found in the {1} file'.format(section, filename))

    return postgis_db 