Show More
@@ -1,53 +1,59 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | from mercurial.hgweb import hgweb |
|
3 | 3 | from mercurial.hgweb.request import wsgiapplication |
|
4 | 4 | from pylons_app.lib.utils import make_ui |
|
5 | from pylons.controllers.util import abort | |
|
6 | from webob.exc import HTTPNotFound | |
|
5 | 7 | class SimpleHg(object): |
|
6 | 8 | |
|
7 | 9 | def __init__(self, application, config): |
|
8 | 10 | self.application = application |
|
9 | 11 | self.config = config |
|
10 | 12 | |
|
11 | 13 | def __call__(self, environ, start_response): |
|
12 | 14 | if not is_mercurial(environ): |
|
13 | 15 | return self.application(environ, start_response) |
|
14 | 16 | else: |
|
15 | #repo_name = environ['PATH_INFO'].replace('/', '') | |
|
17 | try: | |
|
16 | 18 | repo_name = environ['PATH_INFO'].split('/')[1] |
|
17 | if not environ['PATH_INFO'].endswith == '/': | |
|
18 | environ['PATH_INFO'] += '/' | |
|
19 | #environ['SCRIPT_NAME'] = request.path | |
|
19 | except: | |
|
20 | return HTTPNotFound()(environ, start_response) | |
|
21 | ||
|
22 | #since we wrap into hgweb, just reset the path | |
|
20 | 23 | environ['PATH_INFO'] = '/' |
|
21 | 24 | self.baseui = make_ui() |
|
22 | 25 | self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '') |
|
23 | 26 | self.repo_path = os.path.join(self.basepath, repo_name) |
|
27 | try: | |
|
24 | 28 | app = wsgiapplication(self._make_app) |
|
29 | except Exception as e: | |
|
30 | return HTTPNotFound()(environ, start_response) | |
|
25 | 31 | return app(environ, start_response) |
|
26 | 32 | |
|
27 | 33 | def _make_app(self): |
|
28 | 34 | hgserve = hgweb(self.repo_path) |
|
29 | 35 | return self.load_web_settings(hgserve) |
|
30 | 36 | |
|
31 | 37 | |
|
32 | 38 | def load_web_settings(self, hgserve): |
|
33 | 39 | repoui = make_ui(os.path.join(self.repo_path, '.hg', 'hgrc'), False) |
|
34 | 40 | #set the global ui for hgserve |
|
35 | 41 | hgserve.repo.ui = self.baseui |
|
36 | 42 | |
|
37 | 43 | if repoui: |
|
38 | 44 | #set the repository based config |
|
39 | 45 | hgserve.repo.ui = repoui |
|
40 | 46 | |
|
41 | 47 | return hgserve |
|
42 | 48 | |
|
43 | 49 | def is_mercurial(environ): |
|
44 | 50 | """ |
|
45 | 51 | Returns True if request's target is mercurial server - header |
|
46 | 52 | ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. |
|
47 | 53 | """ |
|
48 | 54 | http_accept = environ.get('HTTP_ACCEPT') |
|
49 | 55 | if http_accept and http_accept.startswith('application/mercurial'): |
|
50 | 56 | return True |
|
51 | 57 | return False |
|
52 | 58 | |
|
53 | 59 |
General Comments 0
You need to be logged in to leave comments.
Login now