deluge.config

Deluge Config Module

class deluge.config.Config(filename, defaults=None, config_dir=None)

Bases: object

This class is used to access/create/modify config files

Parameters:
  • filename – the name of the config file
  • defaults – dictionary of default values
  • config_dir – the path to the config directory
__setitem__(key, value)
See set_item()
__getitem__(key)
See get_item()
apply_all()

Calls all set functions

Usage

>>> config = Config("test.conf", defaults={"test": 5})
>>> def cb(key, value):
...     print key, value
...
>>> config.register_set_function("test", cb, apply_now=False)
>>> config.apply_all()
test 5
config
The config dictionary
get_item(key)

Gets the value of item ‘key’

Parameters:
  • key – the item for which you want it’s value
Returns:

the value of item ‘key’

Raises KeyError:
 

if ‘key’ is not in the config dictionary

Usage

>>> config = Config("test.conf", defaults={"test": 5})
>>> config["test"]
5
load(filename=None)

Load a config file

Parameters:
  • filename – if None, uses filename set in object initialization
register_change_callback(callback)

Registers a callback function that will be called when a value is changed in the config dictionary

Parameters:
  • callback – the function, callback(key, value)

Usage

>>> config = Config("test.conf", defaults={"test": 5})
>>> def cb(key, value):
...     print key, value
...
>>> config.register_change_callback(cb)
register_set_function(key, function, apply_now=True)

Register a function to be called when a config value changes

Parameters:
  • key – the item to monitor for change
  • function – the function to call when the value changes, f(key, value)
  • apply_now – if True, the function will be called after it’s registered

Usage

>>> config = Config("test.conf", defaults={"test": 5})
>>> def cb(key, value):
...     print key, value
...
>>> config.register_set_function("test", cb, apply_now=True)
test 5
save(filename=None)

Save configuration to disk

Parameters:
  • filename – if None, uses filename set in object initiliazation
set_item(key, value)

Sets item ‘key’ to ‘value’ in the config dictionary, but does not allow changing the item’s type unless it is None

Parameters:
  • key – string, item to change to change
  • value – the value to change item to, must be same type as what is currently in the config
Raises ValueError:
 

raised when the type of value is not the same as what is currently in the config

Usage

>>> config = Config("test.conf")
>>> config["test"] = 5
>>> config["test"]
5

Previous topic

deluge.common

This Page

Quick search