# Class e.c.c.Config(log.Loggable):

Part of elisa.core.config View In Hierarchy

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

Line # | Kind | Name | Docs
--- | --- | --- | ---
62 | Method | __init__ | Load a config stored in the given file for the given application.
96 | Method | get_config_dir | Config directory name accessor
104 | Method | get_filename | Config filename accessor
112 | Method | set_filename | Config filename setter
147 | Method | get_option | Fetch the option value stored in the given section, at the
166 | Method | set_option | Store an option value under key id at the given section.
184 | Method | del_option | Remove the option identified by key under the specified
201 | Method | write | save the config in a text file (handled by ConfigObj)
221 | Method | rename_section | Rename a section of the config
240 | Method | get_section | Fetch a section from the config
253 | Method | set_section | Store section_data in a new section identified by section_name
277 | Method | del_section | Remove the section identified by section_name
286 | Method | as_dict | Helper method to convert the Config instance to a dictionary

def __init__(self, config_file=None, default_config=''):
overrides elisa.core.log.Loggable.__init__
Load a config stored in the given file for the given application.

Parameters | config_file | the config filename to read (type: string or None. None implies to use CONFIG_DIR/CONFIG_FILE )
Raises | ConfigError | when the config file contains format error

def get_config_dir(self):
Config directory name accessor

Returns | the current config directory absolute path (type: string )

def get_filename(self):
Config filename accessor

Returns | the config filename from which the config has been read (type: string )

def set_filename(self, filename):

Config filename setter

Updates _config_dir and _filename private attributes

Parameters | filename | full path to the config file (type: string )

def get_option(self, key, section='general', default=None):
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 | the option key to look for (type: string )
| section | the section name to search in (type: string )
| default | the default value to use if the option is not found (type: object )
Returns | value of given option in given section (type: object )

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

    Store an option value under key id at the given section.

    @param key:     the option key to look for
    @type key:      string
    @param value:   the value to store under given key
    @type value:    object
    @param section: the section name to search in
    @type section:  string

    @raises L{SectionNotFound} when the given section is not existing

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

    Remove the option identified by key under the specified
    section.

    @param key:     the option key to look for
    @type key:      string
    @param section: the section name to search in
    @type section:  string

    @raises L{SectionNotFound} when the given section is not existing

def write(self, filename=None):
save the config in a text file (handled by ConfigObj)

def rename_section(self, old_name, new_name):

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 | the section to rename (type: string )
| new_name | the new section name (type: string )

def get_section(self, section_name, default=None):
Fetch a section from the config

Parameters | section_name | the section name to look for (type: string )
| default | the default value to use if the section is not found (type: object )
Returns | the ConfigObj section identified by section_name (type: `elisa.extern.configobj.ConfigObj` or empty dict )

def set_section(self, section_name, section={}, doc={}):
Store section_data in a new section identified by section_name in the config

Parameters | section_name | the section name to update (type: string )
| section | the section data (type: dict )
| doc | documentation of section's options (type: dict )

def del_section(self, section_name):
Remove the section identified by section_name

Parameters | section_name | the section name to delete (type: string )

def as_dict(self):
Helper method to convert the Config instance to a dictionary

Returns | a mapping of the config's options by section name (type: dict )