MiscUtils.Configurable | index /usr/local/share/webware/MiscUtils/Configurable.py

`Configurable.py
Provides configuration file functionality.`

Modules

``

os | sys |  |

Classes

``

__builtin__.object
  Configurable
exceptions.Exception(exceptions.BaseException)
  ConfigurationError

class Configurable(__builtin__.object)

``

`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 destination 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'>)
  `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().`

Data descriptors defined here:

__dict__
  `dictionary for instance variables (if defined)`

__weakref__
  `list of weak references to the object (if defined)`

class ConfigurationError(exceptions.Exception)
`` | `Error in configuration file.`

Method resolution order:
  ConfigurationError
  exceptions.Exception
  exceptions.BaseException
  __builtin__.object

Data descriptors defined here:

__weakref__
  `list of weak references to the object (if defined)`

Methods inherited from exceptions.Exception:

__init__(...)
  `x.__init__(...) initializes x; see help(type(x)) for signature`

Data and other attributes inherited from exceptions.Exception:

__new__ = <built-in method __new__ of type object>
  `T.__new__(S, ...) -> a new object with type S, a subtype of T`

Methods inherited from exceptions.BaseException:

__delattr__(...)
  `x.__delattr__('name') <==> del x.name`

__getattribute__(...)
  `x.__getattribute__('name') <==> x.name`

__getitem__(...)
  `x.__getitem__(y) <==> x[y]`

__getslice__(...)
  `x.__getslice__(i, j) <==> x[i:j]
  Use of negative indices is not supported.`

__reduce__(...)

__repr__(...)
  `x.__repr__() <==> repr(x)`

__setattr__(...)
  `x.__setattr__('name', value) <==> x.name = value`

__setstate__(...)

__str__(...)
  `x.__str__() <==> str(x)`

__unicode__(...)

Data descriptors inherited from exceptions.BaseException:

__dict__

args

message

Functions

``

addCommandLineSetting(name, value)
  `Override the configuration with a command-line setting.
  Take a setting, like "AppServer.Verbose=0", and call
  addCommandLineSetting('AppServer.Verbose', '0'), and
  it will override any settings in AppServer.config`

commandLineSetting(configName, settingName, default=<class 'MiscUtils.NoDefault'>)
  `Retrieve a command-line setting.
  You can use this with non-existent classes, like "Context.Root=/WK",
  and then fetch it back with commandLineSetting('Context', 'Root').`