Mercurial > public > src > rhodecode
annotate pylons_app/lib/simplehg.py @ 116:345811faa8a0
Changed simplehg middleware repo name function
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 28 Apr 2010 22:09:33 +0200 |
parents | cc5cf1a93902 |
children | f8ae5c1dfae2 |
rev | line source |
---|---|
111 | 1 import os |
2 from mercurial.hgweb import hgweb | |
3 from mercurial.hgweb.request import wsgiapplication | |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
4 from pylons_app.lib.utils import make_ui |
111 | 5 class SimpleHg(object): |
6 | |
7 def __init__(self, application, config): | |
8 self.application = application | |
9 self.config = config | |
10 | |
11 def __call__(self, environ, start_response): | |
12 if not is_mercurial(environ): | |
13 return self.application(environ, start_response) | |
14 else: | |
116
345811faa8a0
Changed simplehg middleware repo name function
Marcin Kuzminski <marcin@python-works.com>
parents:
114
diff
changeset
|
15 #repo_name = environ['PATH_INFO'].replace('/', '') |
345811faa8a0
Changed simplehg middleware repo name function
Marcin Kuzminski <marcin@python-works.com>
parents:
114
diff
changeset
|
16 repo_name = environ['PATH_INFO'].split('/')[1] |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
17 if not environ['PATH_INFO'].endswith == '/': |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
18 environ['PATH_INFO'] += '/' |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
19 #environ['SCRIPT_NAME'] = request.path |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
20 environ['PATH_INFO'] = '/' |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
21 self.baseui = make_ui() |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
22 self.basepath = self.baseui.configitems('paths')[0][1].replace('*', '') |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
23 self.repo_path = os.path.join(self.basepath, repo_name) |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
24 app = wsgiapplication(self._make_app) |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
25 return app(environ, start_response) |
111 | 26 |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
27 def _make_app(self): |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
28 hgserve = hgweb(self.repo_path) |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
29 return self.load_web_settings(hgserve) |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
30 |
111 | 31 |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
32 def load_web_settings(self, hgserve): |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
33 repoui = make_ui(os.path.join(self.repo_path, '.hg', 'hgrc'), False) |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
34 #set the global ui for hgserve |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
35 hgserve.repo.ui = self.baseui |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
36 |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
37 if repoui: |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
38 #set the repository based config |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
39 hgserve.repo.ui = repoui |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
40 |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
41 return hgserve |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
42 |
111 | 43 def is_mercurial(environ): |
44 """ | |
45 Returns True if request's target is mercurial server - header | |
46 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. | |
47 """ | |
48 http_accept = environ.get('HTTP_ACCEPT') | |
49 if http_accept and http_accept.startswith('application/mercurial'): | |
50 return True | |
51 return False | |
114
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
52 |
cc5cf1a93902
Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents:
111
diff
changeset
|
53 |