Package brisa :: Package core :: Module config :: Class ConfigurationManager
[hide private]
[frames] | no frames]

Class ConfigurationManager

source code

object --+
         |
        ConfigurationManager

Class that provides an easy way of managing configurations.

Configuration is organized in sections, which may contain parameters. Each section has a name and a parameter has a name and a value.

Concerning storage, the configuration can be saved on a sqlite database. Also, there's a feature called "direct access" that enables direct operations on the database. For example, a get_parameter() call would retrieve the value of a parameter directly from the database, if the feature is enabled.

When disabled, all methods apply to (what we call) the "state". The state initially contains the same information that is on the database, but if the "direct access" feature is disabled, all get()'s and set()'s apply to the state. This means you can have a "runtime configuration" and a "static configuration".

By default, the "direct access" feature is disabled. To enable it, just call set_direct_access(True).

The state can be saved on the persistence by explicitly calling manager. save(). It can also update its values by explicitly calling update().

Instance Methods [hide private]
 
__init__(self, config_path='', default_config={})
Constructor for the ConfigurationManager class.
source code
 
set_direct_access(self, access=False)
Sets the direct access option of the ConfigurationManager.
source code
boolean
get_direct_access(self)
Returns False if the ConfigurationManager is currently working on the runtime state.
source code
 
update(self)
Updates the current state of the manager according to persistence data.
source code
 
save(self)
Stores the state of the manager on the persistence.
source code
string
get_parameter(self, section='', parameter='')
Retrieves the value associated with the parameter in the section given.
source code
boolean
get_parameter_bool(self, section='', parameter='')
Retrieves the bool associated with the parameter in the section given.
source code
[]
get_parameter_as_list(self, section='', parameter='', token=':')
Retrieves the list associated with the parameter in the section given.
source code
 
set_parameter(self, section, parameter, par_value=None)
Sets a parameter's value in the given section.
source code
 
rem_section(self, section)
Removes a section given the name.
source code
boolean
contains(self, section, parameter)
Returns wether the given section exists and contains the given parameter.
source code
dictionary
items(self, section)
Returns all the items of the given section.
source code
list
get_section_names(self)
Returns the names of all sections.
source code

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

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, config_path='', default_config={})
(Constructor)

source code 

Constructor for the ConfigurationManager class.

Parameters:
  • config_path (string) - path of the database to work on. If not supplied will work on a memory database.
  • default_config (dict) - default sections and parameters. Keys are section names and values are dicts where keys,value pairs represent a parameter name and value, respectivelly.
Overrides: object.__init__

set_direct_access(self, access=False)

source code 

Sets the direct access option of the ConfigurationManager. When True, direct access makes all get and set methods work directly on the database, not on the current state.

Another short description is: direct access disables the ConfigurationManager state feature.

Parameters:
  • access (boolean) - The direct access option of the ConfigurationManager

get_direct_access(self)

source code 

Returns False if the ConfigurationManager is currently working on the runtime state. Otherwise, it will return True, which means it's working directly on the persistence.

Returns: boolean
The current status of the ConfigurationManager

get_parameter(self, section='', parameter='')

source code 

Retrieves the value associated with the parameter in the section given.

Parameters:
  • section (string) - section to find the parameter
  • parameter (string) - parameter to return the value
Returns: string
the value for the given parameter

get_parameter_bool(self, section='', parameter='')

source code 

Retrieves the bool associated with the parameter in the section given. Returns True in case of 'on', 'yes', '1' or 'True' (False if not on this list).

Parameters:
  • section (string) - section to find the parameter
  • parameter (string) - parameter to return the value
Returns: boolean
the existence or not of the parameter

get_parameter_as_list(self, section='', parameter='', token=':')

source code 

Retrieves the list associated with the parameter in the section given.

Parameters:
  • section (string) - section to find the parameter
  • parameter (string) - parameter where is located the list
  • token (string) - split token for the list
Returns: []
list associated with the parameter

set_parameter(self, section, parameter, par_value=None)

source code 

Sets a parameter's value in the given section. If the parameter does not exist, it gets created.

Parameters:
  • section (string) - section to set the parameter
  • parameter (string) - parameter to set the value
  • par_value (string) - value to be set

rem_section(self, section)

source code 

Removes a section given the name.

Parameters:
  • section (string) - section name to be removed

contains(self, section, parameter)

source code 

Returns wether the given section exists and contains the given parameter.

Parameters:
  • section (string) - section name
  • parameter (string) - parameter to check if present
Returns: boolean
Exitance of the parameter on the given section.

items(self, section)

source code 

Returns all the items of the given section.

Parameters:
  • section (string) - string
Returns: dictionary
all the items of the given section

get_section_names(self)

source code 

Returns the names of all sections.

Returns: list
name of all sections