def read_config(section, variables, sink, filename = None, logvars = False):
global _ETC_PATHS<EOL>import ConfigParser<EOL>config = ConfigParser.ConfigParser()<EOL>if filename is None:<EOL><INDENT>config_files = existing_config_files()<EOL><DEDENT>else:<EOL><INDENT>config_files = []<EOL>for fpath in _ETC_PATHS:<EOL><INDENT>config_files.append("<STR_LIT>" % (fpath, filename))<EOL><DEDENT><DEDENT>config.read(config_files)<EOL>options = {}<EOL>if section in config.sections():<EOL><INDENT>options = config.options(section)<EOL><DEDENT>for varname, value in variables.items():<EOL><INDENT>orig_varname = varname<EOL>varname = varname.lower()<EOL>if varname in options:<EOL><INDENT>try:<EOL><INDENT>if isinstance(value, bool):<EOL><INDENT>value = config.getboolean(section, varname)<EOL><DEDENT>elif isinstance(value, int):<EOL><INDENT>value = config.getint(section, varname)<EOL><DEDENT>elif isinstance(value, float):<EOL><INDENT>value = config.getfloat(section, varname)<EOL><DEDENT>else:<EOL><INDENT>value = config.get(section, varname)<EOL>if len(value) > <NUM_LIT:0>:<EOL><INDENT>value = value.split("<STR_LIT:#>")[<NUM_LIT:0>].strip()<EOL><DEDENT><DEDENT><DEDENT>except:<EOL><INDENT>raise Exception("<STR_LIT>" % orig_varname)<EOL><DEDENT><DEDENT>varname = varname.upper()<EOL>sink.__dict__[varname] = value<EOL>if (logvars):<EOL><INDENT>_LOGGER.debug("<STR_LIT>" % (varname, str(value)))<EOL><DEDENT><DEDENT>
This functions creates a dictionary whose keys are the variables indicated in
'variables' with the values obtained from the config filenames set for this module.

'variables' is a dictionary of variable names and default values { 'VAR1': defaultval1, ...}

The value for the variables is searched under the 'section' section from the configuration
files (all the configuration files: the main one and those included by the config_filter
mechanism)

Sink is a dictionary (or object) that admits each of the variables to be created and set
the value.