pyfarm.agent.config module¶
Configuration¶
Central module for storing and working with a live configuration objects. This module instances ConfigurationWithCallbacks onto config. Attempting to reload this module will not reinstance the config object.
The config object should be directly imported from this module to be used:
>>> from pyfarm.agent.config import config
- class pyfarm.agent.config.LoggingConfiguration(data=None, environment=None, load=True)[source]¶
Bases: pyfarm.core.config.Configuration
Special configuration object which logs when a key is changed in a dictionary. If the reactor is not running then log messages will be queued until they can be emitted so they are not lost.
- _expandvars(value)¶
Performs variable expansion for value. This method is run when a string value is returned from get() or __getitem__(). The default behavior of this method is to recursively expand variables using sources in the following order:
- The environment, os.environ
- The environment (from the configuration), env
- Other values in the configuration
- ~ to the user’s home directory
For example, the following configuration:
foo: foo bar: bar foobar: $foo/$bar path: ~/$foobar/$TEST
Would result in the following assuming $TEST is an environment variable set to somevalue and the current user’s name is user:
{ "foo": "foo", "bar": "bar", "foobar": "foo/bar", "path": "/home/user/foo/bar/somevalue" }
- MODIFIED = 'modified'¶
- CREATED = 'created'¶
- DELETED = 'deleted'¶
- clear()[source]¶
Deletes all keys in this object and triggers a delete event using changed() for each one.
- update(data=None, **kwargs)[source]¶
Updates the data held within this object and triggers the appropriate events with changed().
- class pyfarm.agent.config.ConfigurationWithCallbacks(data=None, environment=None, load=True)[source]¶
Bases: pyfarm.agent.config.LoggingConfiguration
Subclass of LoggingDictionary that provides the ability to run a function when a value is changed.
- callbacks = {}¶
- classmethod register_callback(key, callback, append=False)[source]¶
Register a function as a callback for key. When key is set the given callback will be run by changed()
Parameters:
- classmethod deregister_callback(key, callback)[source]¶
Removes any callback(s) that are registered with the provided key
- clear(callbacks=False)[source]¶
Performs the same operations as dict.clear() except this method can also clear any registered callbacks if requested.