Edgewall Software

Changes between Initial Version and Version 1 of TracDev/PluginDevelopment/ExtensionPoints/trac.env.ISystemInfoProvider


Ignore:
Timestamp:
Jan 22, 2012, 5:02:26 PM (12 years ago)
Author:
Peter Suter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PluginDevelopment/ExtensionPoints/trac.env.ISystemInfoProvider

    v1 v1  
     1== Extension Point : ''ISystemInfoProvider'' ==
     2
     3||'''Interface'''||''ISystemInfoProvider''||'''Since'''||[wiki:TracDev/ApiChanges/0.12#ISystemInfoProvider 0.12]||
     4||'''Module'''||''trac''||'''Source'''||[source:trunk/trac/env.py env.py]||
     5
     6The ''ISystemInfoProvider'' allows reporting system and version information displayed on the [http://trac.edgewall.org/about About Trac] page and in internal error reports.
     7
     8== Purpose ==
     9
     10Trac requires some [TracInstall#MandatoryDependencies mandatory dependencies] and can leverage various [TracInstall#OptionalDependencies 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.
     11
     12Plugins 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.
     13
     14== Usage ==
     15
     16Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment].
     17
     18A class implementing ISystemInfoProvider simply implements the `get_system_info()` method to yield name and version tuples of any used external packages.
     19
     20== Examples ==
     21
     22The following example reports platform information (i.e. the operating system and its version):
     23{{{#!python
     24import platform
     25
     26from trac.core import *
     27from trac.env import ISystemInfoProvider
     28
     29class PlatformInfoProvider(Component):
     30    """Provides platform (Operating System) information."""
     31
     32    implements(ISystemInfoProvider)
     33
     34    def get_system_info(self):
     35        yield platform.system(), platform.version()
     36}}}
     37
     38To 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:
     39{{{#!python
     40from trac.core import *
     41from trac.env import ISystemInfoProvider
     42from trac.util import get_pkginfo
     43
     44class PonyFarm(Component):
     45    """Provides ponies."""
     46
     47    implements(ISystemInfoProvider)
     48
     49    def get_system_info(self):
     50        import pony
     51        yield 'Pony', get_pkginfo(pony).get('version')
     52       
     53     # ...
     54}}}
     55
     56== Available Implementations ==
     57
     58In Trac:
     59 * [browser:trunk/trac/env.py trac.env.Environment]: ''Trac'', ''Python'', SetupTools and PyTz versions
     60 * [browser:trunk/trac/web/chrome.py trac.web.chrome.Chrome]: [http://genshi.edgewall.org/ Genshi] and [http://babel.edgewall.org/ Babel] versions
     61 * [browser:trunk/trac/versioncontrol/svn_fs.py trac.versioncontrol.svn_fs.SubversionConnector]: [TracSubversion Subversion] version
     62 * [browser:trunk/trac/mimeview/rst.py trac.mimeview.rst.ReStructuredTextRenderer]: [WikiRestructuredText Docutils] version
     63 * [browser:trunk/trac/mimeview/pygments.py trac.mimeview.pygments.PygmentsRenderer]: [TracSyntaxColoring#AboutPygments Pygments] version
     64 * [browser:trunk/tracopt/mimeview/silvercity.py tracopt.mimeview.silvercity.SilverCityRenderer]: SilverCity version
     65 
     66In plugins:
     67 * [browser:plugins/0.13/mercurial-plugin/tracext/hg/backend.py tracext.hg.backend.MercurialConnector]: [TracMercurial Mercurial] version
     68
     69== Additional Information and References ==
     70
     71 * [http://www.edgewall.org/docs/trac-trunk/epydoc/trac.env.ISystemInfoProvider-class.html epydoc]
     72 * [http://www.edgewall.org/docs/trac-trunk/html/api/trac_env.html#trac.env.ISystemInfoProvider API Reference]
     73 * Related tickets:
     74  * #8908 Initial implementation
     75 
     76=== Other approaches:
     77Before 0.12 introduced the ISystemInfoProvider interface, it was customary to add version information by calling `self.env.systeminfo.append((name, version))`.
     78
     79(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.)
     80
     81This approach is still used by:
     82* The database backends (so that only the database backend actually used is shown):
     83 * [browser:trunk/trac/db/sqlite_backend.py trac.db.sqlite_backend.SQLiteConnector]: SQLite and pysqlite versions
     84 * [browser:trunk/trac/db/postgres_backend.py trac.db.postgres_backlend.PostgreSQLConnector]: psycopg2 version
     85 * [browser:trunk/trac/db/mysql_backend.py trac.db.mysql_backend.MySQLConnector]: MySQL and MySQLdb versions
     86* [browser:trunk/trac/web/main.py trac.web.main.dispatch_request] for the Web front-end type and version
     87
     88The jQuery version is added client-side by the jQuery Javascript library itself in:
     89 * the [browser:trunk/trac/templates/about.html about.html] template, or
     90 * a combination of the [browser:trunk/trac/web/main.py trac.web.main.send_internal_error()] method (adds a `#JQUERY#` marker) and the [browser:trunk/trac/templates/error.html error.html] template. (See #9341)
     91
     92The ''User Agent'' string is also added to internal error reports client-side by Javascript.