Mercurial > kallithea
comparison pylons_app/controllers/hg.py @ 0:564e40829f80
initial commit.
author | Marcin Kuzminski |
---|---|
date | Thu, 18 Feb 2010 13:01:57 +0100 |
parents | |
children | ad0dd3904225 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:564e40829f80 |
---|---|
1 #!/usr/bin/python | |
2 # -*- coding: utf-8 -*- | |
3 import logging | |
4 from pylons_app.lib.base import BaseController | |
5 from pylons import c, g, session, h, request | |
6 from mako.template import Template | |
7 from pprint import pprint | |
8 #uncomment the following if you want to serve a single repo | |
9 #from mercurial.hgweb.hgweb_mod import hgweb | |
10 from mercurial.hgweb.hgwebdir_mod import hgwebdir | |
11 from mercurial.hgweb.request import wsgiapplication | |
12 log = logging.getLogger(__name__) | |
13 | |
14 #http://bel-epa.com/hg/ | |
15 #def make_web_app(): | |
16 # repos = "hgwebdir.config" | |
17 # hgwebapp = hgwebdir(repos) | |
18 # return hgwebapp | |
19 # | |
20 #class HgController(BaseController): | |
21 # | |
22 # def index(self): | |
23 # hgapp = wsgiapplication(make_web_app) | |
24 # return hgapp(request.environ, self.start_response) | |
25 # | |
26 # def view(self, *args, **kwargs): | |
27 # return u'dupa' | |
28 # #pprint(request.environ) | |
29 # hgapp = wsgiapplication(make_web_app) | |
30 # return hgapp(request.environ, self.start_response) | |
31 | |
32 def _make_app(): | |
33 #for single a repo | |
34 #return hgweb("/path/to/repo", "Name") | |
35 repos = "hgwebdir.config" | |
36 return hgwebdir(repos) | |
37 | |
38 def wsgi_app(environ, start_response): | |
39 start_response('200 OK', [('Content-type', 'text/html')]) | |
40 return ['<html>\n<body>\nHello World!\n</body>\n</html>'] | |
41 | |
42 class HgController(BaseController): | |
43 | |
44 | |
45 | |
46 def view(self, environ, start_response): | |
47 #the following is only needed when using hgwebdir | |
48 app = _make_app() | |
49 #return wsgi_app(environ, start_response) | |
50 response = app(request.environ, self.start_response) | |
51 | |
52 if environ['PATH_INFO'].find("static") != -1: | |
53 return response | |
54 else: | |
55 #wrap the murcurial response in a mako template. | |
56 template = Template("".join(response), | |
57 lookup = environ['pylons.pylons']\ | |
58 .config['pylons.g'].mako_lookup) | |
59 | |
60 return template.render(g = g, c = c, session = session, h = h) | |
61 |