Edgewall Software

Version 2 (modified by Christian Boos, 18 years ago) ( diff )

Introduce the new configuration API for Components

TracDev/ApiChanges/0.10

This page is aimed to help plugin developers to port their 0.9 plugin to Trac 0.10.

General Changes

Use unicode strings

The most important single change in 0.10 was the switch to using unicode everywhere internally.

See TracDev/UnicodeGuidelines.

New Configuration API for Components

Components can still use self.config.get..., but there's now a better way to do this, which among other things make it easy to document your configuration settings.

When you had:

class DoxygenPlugin(Component):
    implements(...)
    # ...
    def match_request(self, req):
        # Get config variables.
        base_path = self.config.get('doxygen', 'path', '/var/lib/trac/doxygen')

You should now write:

class DoxygenPlugin(Component):
    implements(...)
    base_path = Option('doxygen', 'path', '/var/lib/trac/doxygen',
        """Directory containing doxygen generated files.""")

    # ...
    def match_request(self, req):
        base_path = self.base_path 
        # actually, use `self.base_path` where you'd used `base_path`

Besides the string Option, you have also access to more specialized types for you configuration settings, like BoolOption, IntOption, ListOption, etc. (see config.py).

By using the TracIni(doxygen) macro, you'll get the documentation for all your settings.

Interface Changes

ISearchSource (0.10) (0.9)

The get_search_results(self, req, terms, filters) now takes a list of terms instead of the full query, as it used to do for its second argument.

Example: DoxygenPlugin

  • doxygentrac/doxygentrac.py

     
    212212
    213213            yield('doxygen', title)
    214214
    215     def get_search_results(self, req, query, filters):
     215    def get_search_results(self, req, keywords, filters):
    216216        if not 'doxygen' in filters:
    217217            return
    218         if query[0] == query[-1] == "'" or query[0] == query[-1] == '"':
    219             keywords = [query[1:-1]]
    220         else:
    221             keywords = query.split(' ')
    222218
    223219        base_path = self.config.get('doxygen', 'path')

See also: TracDev/ReleaseNotes/0.10

Note: See TracWiki for help on using the wiki.