PylonsHQ.

tomfmason
Dec 6, 2008 12:42:26 AM

Simple Mercurial Controller V2

Language: Python
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import logging
from myapp.lib.base import *
from mako.template import Template
#uncomment the following if you want to serve a single repo
#from mercurial.hgweb.hgweb_mod import hgweb
from mercurial.hgweb.hgwebdir_mod import hgwebdir
log = logging.getLogger(__name__)
class HgController(BaseController):
    """
    This is  a rather simple implementation of a pylons mercurial controller.
    The following are the routes that I used:
    map.connect('/hg', controller='hg', action="view")
    map.connect('/hg/*path_info', controller='hg', action="view")
    """
    def view(self, environ, start_response):
        #the following is only needed when using hgwebdir
        if environ["PATH_INFO"] == "/hg": environ["PATH_INFO"] = ""
        if environ["SCRIPT_NAME"] == "": environ["SCRIPT_NAME"] = "/hg"
        app = self._make_app()
        response = app(environ,start_response)
        if environ['HTTP_ACCEPT'].find("mercurial") >= 0:
            return response
        else:
            #wrap the murcurial response in a mako template.
            template = Template("".join(response), lookup=environ['pylons.pylons'].config['pylons.app_globals'].mako_lookup)
            return template.render(g=g,c=c,session=session, h=h)
    def _make_app(self):
        #for single a repo
        #return hgweb("/path/to/repo", "Name")
        return  hgwebdir("/path/to/hgweb.config")

Download

Comments (0)

You must login before you can comment.

Powered by Pylons - Contact Administrators