comparison pylons_app/lib/simplehg.py @ 114:cc5cf1a93902

Implemented simplehg middleware,moved make_ui functions to lib.utils
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 28 Apr 2010 02:08:45 +0200
parents 70b1e5d1e20d
children 345811faa8a0
comparison
equal deleted inserted replaced
113:b6e219f3a58d 114:cc5cf1a93902
1 import os 1 import os
2
3 import cgi
4 from mercurial import util
5 from mercurial.hgweb.request import wsgirequest, normalize
6 from mercurial.hgweb import hgweb 2 from mercurial.hgweb import hgweb
7 from pylons.controllers.util import Response
8 from mercurial.hgweb.request import wsgiapplication 3 from mercurial.hgweb.request import wsgiapplication
9 4 from pylons_app.lib.utils import make_ui
10
11 class SimpleHg(object): 5 class SimpleHg(object):
12 6
13 def __init__(self, application, config): 7 def __init__(self, application, config):
14 self.application = application 8 self.application = application
15 self.config = config 9 self.config = config
16 10
17 def __call__(self, environ, start_response): 11 def __call__(self, environ, start_response):
18 if not is_mercurial(environ): 12 if not is_mercurial(environ):
19 return self.application(environ, start_response) 13 return self.application(environ, start_response)
20 else: 14 else:
21 from pprint import pprint 15 repo_name = environ['PATH_INFO'].replace('/', '')
22 pprint(environ) 16 if not environ['PATH_INFO'].endswith == '/':
17 environ['PATH_INFO'] += '/'
18 #environ['SCRIPT_NAME'] = request.path
19 environ['PATH_INFO'] = '/'
20 self.baseui = make_ui()
21 self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '')
22 self.repo_path = os.path.join(self.basepath, repo_name)
23 app = wsgiapplication(self._make_app)
24 return app(environ, start_response)
23 25
24 repo_path = os.path.join('/home/marcink/python_workspace/', environ['PATH_INFO'].replace('/', '')) 26 def _make_app(self):
25 def _make_app():return hgweb(repo_path, "Name") 27 hgserve = hgweb(self.repo_path)
26 app = wsgiapplication(_make_app) 28 return self.load_web_settings(hgserve)
27 return app(environ, start_response) 29
28 30
31 def load_web_settings(self, hgserve):
32 repoui = make_ui(os.path.join(self.repo_path, '.hg', 'hgrc'), False)
33 #set the global ui for hgserve
34 hgserve.repo.ui = self.baseui
35
36 if repoui:
37 #set the repository based config
38 hgserve.repo.ui = repoui
39
40 return hgserve
41
29 def is_mercurial(environ): 42 def is_mercurial(environ):
30 """ 43 """
31 Returns True if request's target is mercurial server - header 44 Returns True if request's target is mercurial server - header
32 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. 45 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
33 """ 46 """
34 http_accept = environ.get('HTTP_ACCEPT') 47 http_accept = environ.get('HTTP_ACCEPT')
35 if http_accept and http_accept.startswith('application/mercurial'): 48 if http_accept and http_accept.startswith('application/mercurial'):
36 return True 49 return True
37 return False 50 return False
51
52