Extension Point : ISystemInfoProvider
Interface | ISystemInfoProvider | Since | 0.12 |
Module | trac | Source | env.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:
- trac.env.Environment: Trac, Python, SetupTools and PyTz versions
- trac.web.chrome.Chrome: Genshi and Babel versions
- trac.versioncontrol.svn_fs.SubversionConnector: Subversion version
- trac.mimeview.rst.ReStructuredTextRenderer: Docutils version
- trac.mimeview.pygments.PygmentsRenderer: Pygments version
In plugins:
Additional Information and References
- epydoc
- API Reference
- Related tickets:
- #8908 Initial implementation
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 database backends (so that only the database backend actually used is shown):
- trac.db.sqlite_backend.SQLiteConnector: SQLite and pysqlite versions
- trac.db.postgres_backlend.PostgreSQLConnector: psycopg2 version
- trac.db.mysql_backend.MySQLConnector: MySQL and MySQLdb versions
- trac.web.main.dispatch_request for the Web front-end type and version
The jQuery version is added client-side by the jQuery Javascript library itself in:
- the about.html template, or
- a combination of the trac.web.main.send_internal_error() method (adds a
#JQUERY#
marker) and the error.html template. (See #9341)
The User Agent string is also added to internal error reports client-side by Javascript.