| |
- Configurable
- exceptions.Exception(exceptions.BaseException)
-
- ConfigurationError
class Configurable |
|
Abstract superclass for configuration file functionality.
Subclasses should override:
* defaultConfig() to return a dictionary of default settings
such as { 'Frequency': 5 }
* configFilename() to return the filename by which users can
override the configuration such as
'Pinger.config'
Subclasses typically use the setting() method, for example:
time.sleep(setting('Frequency'))
They might also use the printConfig() method, for example:
printConfig() # or
printConfig(file)
Users of your software can create a file with the same name as
configFilename() and selectively override settings. The format of
the file is a Python dictionary.
Subclasses can also override userConfig() in order to obtain the
user configuration settings from another source. |
|
Methods defined here:
- __init__(self)
- commandLineConfig(self)
- Return the settings that came from the command-line.
These settings come via addCommandLineSetting().
- config(self)
- Return the configuration of the object as a dictionary.
This is a combination of defaultConfig() and userConfig().
This method caches the config.
- configFilename(self)
- Return the full name of the user config file.
Users can override the configuration by this config file.
Subclasses must override to specify a name.
Returning None is valid, in which case no user config file
will be loaded.
- configName(self)
- Return the name of the configuration file without the extension.
This is the portion of the config file name before the '.config'.
This is used on the command-line.
- configReplacementValues(self)
- Return a dictionary for substitutions in the config file.
This must be a dictionary suitable for use with "string % dict"
that should be used on the text in the config file.
If an empty dictionary (or None) is returned, then no substitution
will be attempted.
- defaultConfig(self)
- Return a dictionary with all the default values for the settings.
This implementation returns {}. Subclasses should override.
- hasSetting(self, name)
- Check whether a configuration setting has been changed.
- printConfig(self, dest=None)
- Print the configuration to the given destination.
The default destionation is stdout. A fixed with font is assumed
for aligning the values to start at the same column.
- setSetting(self, name, value)
- Set a particular configuration setting.
- setting(self, name, default=<class MiscUtils.NoDefault at 0x8c81d0>)
- Return the value of a particular setting in the configuration.
- userConfig(self)
- Return the user config overrides.
These settings can be found in the optional config file.
Returns {} if there is no such file.
The config filename is taken from configFilename().
|
|