| |
- Configurable
- exceptions.Exception
-
- ConfigurationError
class Configurable |
|
Configurable is an abstract superclass that provides configuration
file functionality for subclasses.
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)
- Settings that came from the command line (via
addCommandLineSetting).
- config(self)
- Returns the configuration of the object as a dictionary. This is a combination of defaultConfig() and userConfig(). This method caches the config.
- configFilename(self)
- Returns the filename by which users can override the
configuration. Subclasses must override to specify a
name. Returning None is valid, in which case no user
config file will be loaded.
- configName(self)
- Returns the name of the configuration file (the portion
before the '.config'). This is used on the command-line.
- configReplacementValues(self)
- Returns 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)
- Returns a dictionary containing all the default values for the settings. This implementation returns {}. Subclasses should override.
- hasSetting(self, name)
- printConfig(self, dest=None)
- Prints the configuration to the given destination, which defaults to stdout. A fixed with font is assumed for aligning the values to start at the same column.
- setSetting(self, name, value)
- setting(self, name, default=<class MiscUtils.NoDefault>)
- Returns the value of a particular setting in the configuration.
- userConfig(self)
- Returns the user config overrides found in the optional config file, or {} if there is no such file. The config filename is taken from configFilename().
|
|