Builds a configuration reader function

def _read_options(paths,fname_def=None):
    """Builds a configuration reader function"""
    def reader_func(fname=fname_def, sect=None, sett=None, default=None):
        """Reads the configuration for trump"""

        cur_dir = os.path.dirname(os.path.realpath(__file__))
        config_dir = os.path.join(cur_dir, *paths)

        config_files = [(f[:-4], f)
                        for f in os.listdir(config_dir) if f[-4:] == ".cfg"]
        sample_files = [(f[:-11], f)
                        for f in os.listdir(config_dir) if f[-11:] == ".cfg_sample"]

        if fname:
            config_files = [f for f in config_files if f[0] == fname]
            sample_files = [f for f in sample_files if f[0] == fname]


        config_files = dict(config_files)
        sample_files = dict(sample_files)

        cfg_files = sample_files
        for fn, f in config_files.iteritems():
            cfg_files[fn] = f

        sample_files_exposed = []

        confg = {}

        for src, fil in cfg_files.iteritems():
            confg[src] = {}
            cfpr = ConfigParser.ConfigParser()
            cfpr.read(os.path.join(config_dir, fil))
            for sec in cfpr.sections():
                confg[src][sec] = dict(cfpr.items(sec))

            if ".cfg_sample" in fil:
                sample_files_exposed.append(fil)


        if len(sample_files_exposed) > 0:
            msg = ", ".join(sample_files_exposed)
            body = "{} sample configuration files have been exposed. " \
                  "Rename *.cfg_sample to *.cfg, and populate the " \
                  "correct settings in the config and settings " \
                  "directories to avoid this warning."
            msg = body.format(msg)
            warnings.warn(msg)

        keys = []

        if fname:
            keys.append(fname)
            if sect:
                keys.append(sect)
                if sett:
                    keys.append(sett)
        try:
            return get_from_nested(keys, confg)
        except KeyError:
            if default is not None:
                return default
            else:
                raise

    return reader_func