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