30 lines
970 B
Python
30 lines
970 B
Python
#! /usr/bin/python
|
|
from trac.core import *
|
|
from trac.web.api import IRequestFilter
|
|
|
|
from trac.web.chrome import add_ctxtnav, add_notice
|
|
|
|
class RepoLinkModule(Component):
|
|
"""Show a link to the repository in the source browser."""
|
|
|
|
implements(IRequestFilter)
|
|
|
|
def __init__(self):
|
|
Component.__init__(self)
|
|
self.base = self.config.get('trac', 'repository_url')
|
|
if self.base.endswith('/'):
|
|
self.base = self.base[:-1]
|
|
|
|
def pre_process_request(self, req, handler):
|
|
return (handler)
|
|
|
|
def post_process_request(self, req, template, data, content_type):
|
|
if self.base and req.path_info.startswith('/browser/'):
|
|
name = req.path_info[9:].split('/')[0]
|
|
if name:
|
|
href = self.base + '/' + name
|
|
add_ctxtnav(req, "Repo", href = href)
|
|
add_notice(req, "checkout %s with: bzr branch %s"%(name, href))
|
|
|
|
return (template, data, content_type)
|