trac.config¶
-
class
trac.config.Configuration(filename, params={})¶ Bases:
objectThin layer over
ConfigParserfrom 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.
-
defaults(compmgr=None)¶ Returns a dictionary of the default configuration values.
If
compmgris specified, return only options declared in components that are enabled in the givenComponentManager.
-
exists¶ Return boolean indicating configuration file existence.
Since: 1.0.11
-
get(section, key, default='')¶ Return the value of the specified option.
Valid default input is a string. Returns a string.
-
getbool(section, key, default='')¶ 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, otherwiseFalse.Valid default input is a string or a bool. Returns a bool.
-
getfloat(section, key, default='')¶ Return the value of the specified option as float.
If the specified option can not be converted to a float, a
ConfigurationErrorexception is raised.Valid default input is a string, float or int. Returns a float.
-
getint(section, key, default='')¶ Return the value of the specified option as integer.
If the specified option can not be converted to an integer, a
ConfigurationErrorexception is raised.Valid default input is a string or an int. Returns an int.
-
getlist(section, key, default='', sep=', ', keep_empty=False)¶ Return a list of values that have been specified as a single comma-separated option.
A different separator can be specified using the
sepparameter. Thesepparameter can specify multiple values using a list or a tuple. If thekeep_emptyparameter is set toTrue, empty elements are included in the list.Valid default input is a string or a list. Returns a string.
-
getpath(section, key, default='')¶ 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.
-
has_option(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.
-
options(section, compmgr=None)¶ 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
compmgris specified, only return default option values for components that are enabled in the givenComponentManager.
-
remove(section, key)¶ Remove the specified option.
-
save()¶ Write the configuration options to the primary file.
-
sections(compmgr=None, defaults=True, empty=False)¶ Return a list of section names.
If
compmgris specified, only the section names corresponding to options declared in components that are enabled in the givenComponentManagerare returned.Parameters: empty – If True, include sections from the registry that contain no options.
-
set(section, key, value)¶ Change a configuration value.
These changes are not persistent unless saved with
save().
-
set_defaults(compmgr=None, component=None)¶ 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 overwritten.
-
-
class
trac.config.ConfigSection(name, doc, doc_domain='tracini', doc_args=None)¶ Bases:
objectDescriptor for configuration sections.
Create the configuration section.
-
doc¶ Return localized document of the section
-
static
get_registry(compmgr=None)¶ Return the section registry, as a
dictmapping section names toConfigSectionobjects.If
compmgris specified, only return sections for components that are enabled in the givenComponentManager.
-
-
class
trac.config.Option(section, name, default=None, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
objectDescriptor for configuration options.
Create the configuration option.
Parameters: - section – the name of the configuration section this option belongs to
- name – the name of the option
- default – the default value for the option
- doc – documentation of the option
-
doc¶ Return localized document of the option
-
dumps(value)¶ Return the value as a string to write to a trac.ini file
-
static
get_registry(compmgr=None)¶ Return the option registry, as a
dictmapping(section, key)tuples toOptionobjects.If
compmgris specified, only return options for components that are enabled in the givenComponentManager.
-
normalize(value)¶ Normalize the given value to write to a trac.ini file
-
class
trac.config.BoolOption(section, name, default=None, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
trac.config.OptionDescriptor for boolean configuration options.
Create the configuration option.
Parameters: - section – the name of the configuration section this option belongs to
- name – the name of the option
- default – the default value for the option
- doc – documentation of the option
-
class
trac.config.IntOption(section, name, default=None, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
trac.config.OptionDescriptor for integer configuration options.
Create the configuration option.
Parameters: - section – the name of the configuration section this option belongs to
- name – the name of the option
- default – the default value for the option
- doc – documentation of the option
-
class
trac.config.FloatOption(section, name, default=None, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
trac.config.OptionDescriptor for float configuration options.
Create the configuration option.
Parameters: - section – the name of the configuration section this option belongs to
- name – the name of the option
- default – the default value for the option
- doc – documentation of the option
-
class
trac.config.ListOption(section, name, default=None, sep=', ', keep_empty=False, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
trac.config.OptionDescriptor for configuration options that contain multiple values separated by a specific character.
-
class
trac.config.ChoiceOption(section, name, choices, doc='', doc_domain='tracini', doc_args=None, case_sensitive=True)¶ Bases:
trac.config.OptionDescriptor for configuration options providing a choice among a list of items.
The default value is the first choice in the list.
-
class
trac.config.PathOption(section, name, default=None, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
trac.config.OptionDescriptor for file system path configuration options.
Relative paths are resolved to absolute paths using the directory containing the configuration file as the reference.
Create the configuration option.
Parameters: - section – the name of the configuration section this option belongs to
- name – the name of the option
- default – the default value for the option
- doc – documentation of the option
-
class
trac.config.ExtensionOption(section, name, interface, default=None, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
trac.config.OptionName of a component implementing
interface. Raises aConfigurationErrorif the component cannot be found in the list of active components implementing the interface.
-
class
trac.config.OrderedExtensionsOption(section, name, interface, default=None, include_missing=True, doc='', doc_domain='tracini', doc_args=None)¶ Bases:
trac.config.ListOptionA comma separated, ordered, list of components implementing
interface. Can be empty.If
include_missingis true (the default) all components implementing the interface are returned, with those specified by the option ordered first.
-
exception
trac.config.ConfigurationError(message=None, title=None, show_traceback=False)¶ Bases:
trac.core.TracErrorException raised when a value in the configuration file is not valid.
-
class
trac.config.UnicodeConfigParser(ignorecase_option=True, **kwargs)¶ Bases:
ConfigParser.ConfigParserA Unicode-aware version of ConfigParser. Arguments are encoded to UTF-8 and return values are decoded from UTF-8.
-
class
trac.config.Section(config, name)¶ Bases:
objectProxy for a specific configuration section.
Objects of this class should not be instantiated directly.
-
get(key, default='')¶ Return the value of the specified option.
Valid default input is a string. Returns a string.
-
getbool(key, default='')¶ Return the value of the specified option as boolean.
This method returns
Trueif the option value is one of “yes”, “true”, “enabled”, “on”, or non-zero numbers, ignoring case. OtherwiseFalseis returned.Valid default input is a string or a bool. Returns a bool.
-
getfloat(key, default='')¶ Return the value of the specified option as float.
If the specified option can not be converted to a float, a
ConfigurationErrorexception is raised.Valid default input is a string, float or int. Returns a float.
-
getint(key, default='')¶ Return the value of the specified option as integer.
If the specified option can not be converted to an integer, a
ConfigurationErrorexception is raised.Valid default input is a string or an int. Returns an int.
-
getlist(key, default='', sep=', ', keep_empty=True)¶ Return a list of values that have been specified as a single comma-separated option.
A different separator can be specified using the
sepparameter. Thesepparameter can specify multiple values using a list or a tuple. If thekeep_emptyparameter is set toTrue, empty elements are included in the list.Valid default input is a string or a list. Returns a list.
-
getpath(key, default='')¶ Return the value of the specified option as a path, relative to the location of this configuration file.
Valid default input is a string. Returns a normalized path.
-
iterate(compmgr=None, defaults=True)¶ Iterate over the options in this section.
If
compmgris specified, only return default option values for components that are enabled in the givenComponentManager.
-
options(compmgr=None)¶ Return
(key, value)tuples for every option in the section.This includes options that have default values that haven’t been overridden. If
compmgris specified, only return default option values for components that are enabled in the givenComponentManager.
-
remove(key)¶ Delete a key from this section.
Like for
set(), the changes won’t persist untilsave()gets called.
-
set(key, value)¶ Change a configuration value.
These changes are not persistent unless saved with
save().
-
-
trac.config.get_configinfo(env)¶ Returns a list of dictionaries containing the
nameandoptionsof each configuration section. The value ofoptionsis a list of dictionaries containing thename,valueandmodifiedstate of each configuration option. Themodifiedvalue is True if the value differs from its default.Since: version 1.1.2
Components¶
-
class
trac.config.ConfigurationAdmin¶ Bases:
trac.core.Componenttrac-admin command provider for trac.ini administration.