Package trac :: Module config :: Class Configuration

Class Configuration

source code

object --+
         |
        Configuration

Thin layer over ConfigParser from the Python standard library.

In addition to providing some convenience methods, the class remembers the last modification time of the configuration file, and reparses it when the file has changed.

Instance Methods
 
__init__(self, filename, params={})
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__contains__(self, name)
Return whether the configuration contains a section of the given name.
source code
 
__getitem__(self, name)
Return the configuration section with the specified name.
source code
 
__repr__(self)
repr(x)
source code
 
get(self, section, key, default='')
Return the value of the specified option.
source code
 
getbool(self, section, key, default='')
Return the specified option as boolean value.
source code
 
getint(self, section, key, default='')
Return the value of the specified option as integer.
source code
 
getfloat(self, section, key, default='')
Return the value of the specified option as float.
source code
 
getlist(self, section, key, default='', sep=',', keep_empty=False)
Return a list of values that have been specified as a single comma-separated option.
source code
 
getpath(self, section, key, default='')
Return a configuration value as an absolute path.
source code
 
set(self, section, key, value)
Change a configuration value.
source code
 
defaults(self, compmgr=None)
Returns a dictionary of the default configuration values (''since 0.10'').
source code
 
options(self, section, compmgr=None)
Return a list of (name, value) tuples for every option in the specified section.
source code
 
remove(self, section, key)
Remove the specified option.
source code
 
sections(self, compmgr=None, defaults=True)
Return a list of section names.
source code
 
has_option(self, section, option, defaults=True)
Returns True if option exists in section in either the project trac.ini or one of the parents, or is available through the Option registry.
source code
 
save(self)
Write the configuration options to the primary file.
source code
 
parse_if_needed(self, force=False) source code
 
touch(self) source code
 
set_defaults(self, compmgr=None)
Retrieve all default values and store them explicitly in the configuration, so that they can be saved to file.
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties
  exists
Return boolean indicating configuration file existence.

Inherited from object: __class__

Method Details

__init__(self, filename, params={})
(Constructor)

source code 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__
(inherited documentation)

__repr__(self)
(Representation operator)

source code 
repr(x)
Overrides: object.__repr__
(inherited documentation)

get(self, section, key, default='')

source code 

Return the value of the specified option.

Valid default input is a string. Returns a string.

getbool(self, section, key, default='')

source code 

Return the specified option as boolean value.

If the value of the option is one of "yes", "true", "enabled", "on", or "1", this method wll return True, otherwise False.

Valid default input is a string or a bool. Returns a bool.

(since Trac 0.9.3, "enabled" added in 0.11)

getint(self, section, key, default='')

source code 

Return the value of the specified option as integer.

If the specified option can not be converted to an integer, a ConfigurationError exception is raised.

Valid default input is a string or an int. Returns an int.

(since Trac 0.10)

getfloat(self, section, key, default='')

source code 

Return the value of the specified option as float.

If the specified option can not be converted to a float, a ConfigurationError exception is raised.

Valid default input is a string, float or int. Returns a float.

(since Trac 0.12)

getlist(self, section, key, default='', sep=',', keep_empty=False)

source code 

Return a list of values that have been specified as a single comma-separated option.

A different separator can be specified using the sep parameter. If the keep_empty parameter is set to True, empty elements are included in the list.

Valid default input is a string or a list. Returns a string.

(since Trac 0.10)

getpath(self, section, key, default='')

source code 

Return a configuration value as an absolute path.

Relative paths are resolved relative to the location of this configuration file.

Valid default input is a string. Returns a normalized path.

(enabled since Trac 0.11.5)

set(self, section, key, value)

source code 

Change a configuration value.

These changes are not persistent unless saved with save().

defaults(self, compmgr=None)

source code 

Returns a dictionary of the default configuration values (''since 0.10'').

If compmgr is specified, return only options declared in components that are enabled in the given ComponentManager.

options(self, section, compmgr=None)

source code 

Return a list of (name, value) tuples for every option in the specified section.

This includes options that have default values that haven't been overridden. If compmgr is specified, only return default option values for components that are enabled in the given ComponentManager.

sections(self, compmgr=None, defaults=True)

source code 

Return a list of section names.

If compmgr is specified, only the section names corresponding to options declared in components that are enabled in the given ComponentManager are returned.

has_option(self, section, option, defaults=True)

source code 

Returns True if option exists in section in either the project trac.ini or one of the parents, or is available through the Option registry.

(since Trac 0.11)

set_defaults(self, compmgr=None)

source code 

Retrieve all default values and store them explicitly in the configuration, so that they can be saved to file.

Values already set in the configuration are not overridden.


Property Details

exists

Return boolean indicating configuration file existence.
Get Method:
unreachable.exists(self) - Return boolean indicating configuration file existence.

Since: 1.0.11