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'
pop(key, *args)[source]

Deletes the provided key and triggers a delete event using changed().

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().

changed(change_type, key, new_value=<object object>, old_value=<object object>)[source]

This method is run whenever one of the keys in this object changes.

master_contacted(update=True, announcement=False)[source]

Simple method that will update the last_master_contact and then return the result.

Parameters:update (bool) – Setting this value to False will just return the current value instead of updating the value too.
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:
  • key (string) – the key which when changed in any way will execute callback
  • callback (callable) – the function or method to register
  • append (boolean) – by default attempting to register a callback which has already been registered will do nothing, setting this to True overrides this behavior.
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.

changed(change_type, key, new_value=<object object>, old_value=<object object>)[source]

This method is called internally whenever a given key changes which in turn will pass off the change to any registered callback(s).

pyfarm.agent.config.configure_logger_level()[source]

When called this will set the root logger level based on the agent_global_logger_level configuration variable.