Package elisa :: Package core :: Module config :: Class Config
[hide private]
[frames] | no frames]

Class Config

source code


Configuration system

Each configuration is stored in a text file. The configuration is structured in sections. Each section stores a set of options. Example:
 [section_name]
 some_list = ['some','list']
 some_string = 'foobar'
 some_int = 1


Instance Methods [hide private]
 
__init__(self, config_file='frontend', default_config='')
Load a config stored in the given file for the given application.
source code
string
get_config_dir(self)
Config directory name accessor
source code
string
get_filename(self)
Config filename accessor
source code
 
set_filename(self, filename)
Config filename setter
source code
 
_create_config(self, config_file, default_config) source code
object
get_option(self, key, section='general', default='frontend')
Fetch the option value stored in the given section, at the given key.
source code
 
set_option(self, key, value, section='general')
Store an option value under key id at the given section.
source code
 
del_option(self, key, section='general')
Remove the option identified by key under the specified section.
source code
 
write(self, filename='frontend')
save the config in a text file (handled by ConfigObj)
source code
 
rename_section(self, old_name, new_name)
Rename a section of the config
source code
elisa.extern.configobj.ConfigObj or empty dict
get_section(self, section_name, default='frontend')
Fetch a section from the config
source code
 
set_section(self, section_name, section={}, doc={})
Store section_data in a new section identified by section_name in the config
source code
 
del_section(self, section_name)
Remove the section identified by section_name
source code
dict
as_dict(self)
Helper method to convert the Config instance to a dictionary
source code

Inherited from extern.log.log.Loggable: debug, doLog, error, info, log, logFunction, logObjectName, warning, warningFailure

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]

Inherited from extern.log.log.Loggable: logCategory

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, config_file='frontend', default_config='')
(Constructor)

source code 
Load a config stored in the given file for the given application.
Parameters:
  • config_file (string or None. None implies to use CONFIG_DIR/CONFIG_FILE) - the config filename to read
Raises:
  • ConfigError - when the config file contains format error
Overrides: log.Loggable.__init__

get_config_dir(self)

source code 
Config directory name accessor
Returns: string
the current config directory absolute path

get_filename(self)

source code 
Config filename accessor
Returns: string
the config filename from which the config has been read

set_filename(self, filename)

source code 

Config filename setter

Updates _config_dir and _filename private attributes
Parameters:
  • filename (string) - full path to the config file

get_option(self, key, section='general', default='frontend')

source code 
Fetch the option value stored in the given section, at the given key. Return a default value if the key is not found.
Parameters:
  • key (string) - the option key to look for
  • section (string) - the section name to search in
  • default (object) - the default value to use if the option is not found
Returns: object
value of given option in given section

set_option(self, key, value, section='general')

source code 
Store an option value under key id at the given section.
Parameters:
  • key (string) - the option key to look for
  • value (object) - the value to store under given key
  • section (string) - the section name to search in

del_option(self, key, section='general')

source code 
Remove the option identified by key under the specified section.
Parameters:
  • key (string) - the option key to look for
  • section (string) - the section name to search in

rename_section(self, old_name, new_name)

source code 

Rename a section of the config

Options and comments stored in the section are kept intact. The config is update in-place. No result is returned by this method.
Parameters:
  • old_name (string) - the section to rename
  • new_name (string) - the new section name

get_section(self, section_name, default='frontend')

source code 
Fetch a section from the config
Parameters:
  • section_name (string) - the section name to look for
  • default (object) - the default value to use if the section is not found
Returns: elisa.extern.configobj.ConfigObj or empty dict
the ConfigObj section identified by section_name

set_section(self, section_name, section={}, doc={})

source code 
Store section_data in a new section identified by section_name in the config
Parameters:
  • section_name (string) - the section name to update
  • section (dict) - the section data
  • doc (dict) - documentation of section's options

del_section(self, section_name)

source code 
Remove the section identified by section_name
Parameters:
  • section_name (string) - the section name to delete

as_dict(self)

source code 
Helper method to convert the Config instance to a dictionary
Returns: dict
a mapping of the config's options by section name