Package mvpa :: Package base :: Module config :: Class ConfigManager
[hide private]
[frames] | no frames]

Class ConfigManager

source code


Central configuration registry for PyMVPA.

The purpose of this class is to collect all configurable settings used by various parts of PyMVPA. It is fairly simple and does only little more than the standard Python ConfigParser. Like ConfigParser it is blind to the data that it stores, i.e. not type checking is performed.

Configuration files (INI syntax) in multiple location are passed when the class is instanciated or whenever Config.reload() is called later on. By default it looks for a config file named pymvpa.cfg in the current directory and .pymvpa.cfg in the user's home directory. Morever, the constructor takes an optional argument with a list of additional file names to parse.

In addition to configuration files, this class also looks for special environment variables to read settings from. Names of such variables have to start with MVPA_ following by the an optional section name and the variable name itself ('_' as delimiter). If no section name is provided, the variables will be associated with section general. Some examples:

MVPA_VERBOSE=1

will become:

[general]
verbose = 1

However, MVPA_VERBOSE_OUTPUT=stdout becomes:

[verbose]
output = stdout

Any lenght of variable name as allowed, e.g. MVPA_SEC1_LONG_VARIABLE_NAME=1 becomes:

[sec1]
long variable name = 1

Settings from custom configuration files (specified by the constructor argument) have the highest priority and override settings found in the current directory. They in turn override user-specific settings and finally the content of any MVPA_* environment variables overrides all settings read from any file.

Instance Methods [hide private]
 
__init__(self, filenames=None)
Initialization reads settings from config files and env. variables.
source code
 
reload(self)
Re-read settings from all configured locations.
source code
 
__repr__(self)
Generate INI file content with current configuration.
source code
 
save(self, filename)
Write current configuration to a file.
source code
 
get(self, section, option, default=None, **kwargs)
Wrapper around SafeConfigParser.get() with a custom default value.
source code
 
getboolean(self, section, option, default=None)
Wrapper around SafeConfigParser.getboolean() with a custom default.
source code
 
getAsDType(self, section, option, dtype, default=None)
Convenience method to query options with a custom default and type
source code

Inherited from ConfigParser.SafeConfigParser: set

Inherited from ConfigParser.SafeConfigParser (private): _interpolate, _interpolate_some

Inherited from ConfigParser.ConfigParser: items

Inherited from ConfigParser.ConfigParser (private): _interpolation_replace

Inherited from ConfigParser.RawConfigParser: add_section, defaults, getfloat, getint, has_option, has_section, options, optionxform, read, readfp, remove_option, remove_section, sections, write

Inherited from ConfigParser.RawConfigParser (private): _get, _read

Class Variables [hide private]
  _DEFAULTS = {'general': {'verbose': '1',}}

Inherited from ConfigParser.SafeConfigParser (private): _interpvar_re

Inherited from ConfigParser.ConfigParser (private): _KEYCRE

Inherited from ConfigParser.RawConfigParser: OPTCRE, OPTCRE_NV, SECTCRE

Inherited from ConfigParser.RawConfigParser (private): _boolean_states

Method Details [hide private]

__init__(self, filenames=None)
(Constructor)

source code 
Initialization reads settings from config files and env. variables.
Overrides: ConfigParser.RawConfigParser.__init__

Parameters: filenames: list of filenames

get(self, section, option, default=None, **kwargs)

source code 

Wrapper around SafeConfigParser.get() with a custom default value.

This method simply wraps the base class method, but adds a default keyword argument. The value of default is returned whenever the config parser does not have the requested option and/or section.

Overrides: ConfigParser.RawConfigParser.get

getboolean(self, section, option, default=None)

source code 

Wrapper around SafeConfigParser.getboolean() with a custom default.

This method simply wraps the base class method, but adds a default keyword argument. The value of default is returned whenever the config parser does not have the requested option and/or section.

Overrides: ConfigParser.RawConfigParser.getboolean

getAsDType(self, section, option, dtype, default=None)

source code 

Convenience method to query options with a custom default and type

This method simply wraps the base class method, but adds a default keyword argument. The value of default is returned whenever the config parser does not have the requested option and/or section.

In addition, the returned value is converted into the specified dtype.