Edgewall Software

Changes between Version 3 and Version 4 of TracDev/ConfigApi


Ignore:
Timestamp:
Jan 7, 2011, 6:46:26 PM (13 years ago)
Author:
Sebastian Krysmanski <sebastian@…>
Comment:

listing known options

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/ConfigApi

    v3 v4  
    6262}}}
    6363
    64 == Defining options ==
     64== Defining options == #defining_options
    6565While you can use `config.set()` to store values for arbitrary options, there's also a way to tell Trac which options are available. To do this, create a component and specify the option like this:
    6666
     
    165165}}}
    166166
    167 == Listing available options == #listing_options
     167== Listing known options == #listing_options
     168Beside retrieving the value of a certain option, there are also methods for listing all known options.
     169
     170 * `config.sections()`: Returns a list of the names of all known sections.
     171 * `config.options(section_name)`: Returns a list of `(name, value)` tuples for all known options in the specified section.
     172 * `config.defaults()`: Returns a dict with the default values of all known options (that have one) in all known sections.
     173
     174A "known option" in this context is an option that
     175
     176 * is defined like described in the section [#defining_options Defining Options] above
     177 * and/or has value assigned to it.
     178
     179Furthermore, there is a way to list all ''defined'' options. This is done by using `Option.registry` which is a dict with `(section_name, option_name)` keys. The value for each key is the `Option` object that defines the option (not its current value). The following example will list the descriptions of all defined options:
     180
     181{{{
     182#!python
     183for (section_name, option_name), option in Option.registry.items():
     184    print option.__doc__
     185}}}