Edgewall Software

Version 1 (modified by Peter Suter, 12 years ago) ( diff )

Extension Point : ISystemInfoProvider

InterfaceISystemInfoProviderSince0.12
ModuletracSourceenv.py

The ISystemInfoProvider allows reporting system and version information displayed on the About Trac page and in internal error reports.

Purpose

Trac requires some mandatory dependencies and can leverage various optional dependencies. Further, plugins can add their own dependencies. For administration and debugging purposes these dependencies and the respective version information is gathered and shown in the appropriate places.

Plugins can add additional such information by implementing ISystemInfoProvider. Note that the plugins themselves and their respective versions are already listed automatically, so plugins should only implement this interface to report additional version information of external dependencies.

Usage

Implementing the interface follows the standard guidelines found in TracDev/ComponentArchitecture and of course TracDev/PluginDevelopment.

A class implementing ISystemInfoProvider simply implements the get_system_info() method to yield name and version tuples of any used external packages.

Examples

The following example reports platform information (i.e. the operating system and its version):

import platform

from trac.core import *
from trac.env import ISystemInfoProvider

class PlatformInfoProvider(Component):
    """Provides platform (Operating System) information."""

    implements(ISystemInfoProvider)

    def get_system_info(self):
        yield platform.system(), platform.version()

To automatically extract the version of a Python library package, use the trac.util.get_pkginfo utility method. For example an imaginary pony library could be reported as follows:

from trac.core import *
from trac.env import ISystemInfoProvider
from trac.util import get_pkginfo

class PonyFarm(Component):
    """Provides ponies."""

    implements(ISystemInfoProvider)

    def get_system_info(self):
        import pony
        yield 'Pony', get_pkginfo(pony).get('version')
        
     # ...

Available Implementations

In Trac:

In plugins:

Additional Information and References

Other approaches:

Before 0.12 introduced the ISystemInfoProvider interface, it was customary to add version information by calling self.env.systeminfo.append((name, version)).

(While this is still possible, it is usually preferrable to implement the interface to ensure that the version is shown even if the respective component has not otherwise been used yet.)

This approach is still used by:

The jQuery version is added client-side by the jQuery Javascript library itself in:

The User Agent string is also added to internal error reports client-side by Javascript.

Note: See TracWiki for help on using the wiki.