import configparser


def parse_cfg(cfgfile):
    """Parse config file and return nested dictionary. """
    parser = configparser.ConfigParser()
    parser.read(cfgfile)

    settings = {}
    for section in parser.sections():
        settings[section] = {}
        for option in parser.options(section):
            try:
                settings[section][option] = parser.get(section, option)
            except:
                settings[section][option] = None                
    return settings