2. lib.configuration — Configuration

class lib.configuration.ConfigurationManager[source]

Bases: lib.utils.Observable

This object manages sotring and accessing configurations.

This object stores individual configurations on a 2-level hierarchy and enables the configurations to be ordered using an arbitary priority system.

The 2 levels are named service_name and source_name to represent the service and the source of the configuration respectively. All configurations under a common service_name are agregated using the ServiceConfigurationWrapper which allows for easy access to individual configuration items.

The priority given to set_config is taken to mean that the larger(numerically) the number, the more important it is. So in the case where 2 configurations provide the same key; the configuration with the larger priority number will be used.

Note

For every successful modification, the observers are notified with 2 parameters: self and the service name that is affected.

Warning

A notification of modification may not actually affect the data.

Variables:configs – A dict storing all the configurations.
get_config(service_name)[source]

Gets the service’s configuration wrapped in a ServiceConfigurationWrapper.

Parameters:service_name – The name of the service.
Returns:A read only dictionary like object that manages retrieving the configuration in a transparent manner.
set_config(service_name, source_name, source_priority, new_config)[source]

Assigns the given configuration to the service’s configuration.

If there is an existing (service_name, source_name) pair then it will be overwritten with the values given. The source name can be reused over multiple service names without any ill effects.

Parameters:
  • service_name – The name of the service.
  • source_name – The name of the source.
  • source_priority – The priority of the source.
  • new_config – A mapping containing the configuration.
delete_config(service_name, source_name=None)[source]

Removes all configurations under service_name and if specified source_name. If source_name is not specified all configurations a removed.

No operation is performed if service_name is missing, the same applies if the pair service_name and source_name are missing.

All observers are notified if data is removed.

Parameters:
  • service_name – The name of the service to remove.
  • source_name – The name of source to remove.
class lib.configuration.ServiceConfigurationWrapper(config_manager, service_name)[source]

Bases: lib.utils.AbstractPriorityDictionary, lib.utils.Observable

An immutable dictionary which allows easier access to the values stored in ConfigurationManager.

It preferable to use get_config to create an instance of this class.

Warning

A notification of modification may not actually affect the data.

See also

AbstractPriorityDictionary for more information about the avaliable functions.