Show More
@@ -1,13 +1,7 b'' | |||
|
1 | 1 | import os |
|
2 | ||
|
3 | import cgi | |
|
4 | from mercurial import util | |
|
5 | from mercurial.hgweb.request import wsgirequest, normalize | |
|
6 | 2 | from mercurial.hgweb import hgweb |
|
7 | from pylons.controllers.util import Response | |
|
8 | 3 | from mercurial.hgweb.request import wsgiapplication |
|
9 | ||
|
10 | ||
|
4 | from pylons_app.lib.utils import make_ui | |
|
11 | 5 | class SimpleHg(object): |
|
12 | 6 | |
|
13 | 7 | def __init__(self, application, config): |
@@ -18,14 +12,33 b' class SimpleHg(object):' | |||
|
18 | 12 | if not is_mercurial(environ): |
|
19 | 13 | return self.application(environ, start_response) |
|
20 | 14 | else: |
|
21 | from pprint import pprint | |
|
22 | pprint(environ) | |
|
15 | repo_name = environ['PATH_INFO'].replace('/', '') | |
|
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('/', '')) | |
|
25 | def _make_app():return hgweb(repo_path, "Name") | |
|
26 | app = wsgiapplication(_make_app) | |
|
27 | return app(environ, start_response) | |
|
26 | def _make_app(self): | |
|
27 | hgserve = hgweb(self.repo_path) | |
|
28 | return self.load_web_settings(hgserve) | |
|
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 | 42 | def is_mercurial(environ): |
|
30 | 43 | """ |
|
31 | 44 | Returns True if request's target is mercurial server - header |
@@ -35,3 +48,5 b' def is_mercurial(environ):' | |||
|
35 | 48 | if http_accept and http_accept.startswith('application/mercurial'): |
|
36 | 49 | return True |
|
37 | 50 | return False |
|
51 | ||
|
52 |
@@ -1,3 +1,6 b'' | |||
|
1 | from mercurial import ui, config | |
|
2 | import os | |
|
3 | import logging | |
|
1 | 4 | |
|
2 | 5 | def get_repo_slug(request): |
|
3 | 6 | path_info = request.environ.get('PATH_INFO') |
@@ -14,3 +17,59 b' def is_mercurial(environ):' | |||
|
14 | 17 | if http_accept and http_accept.startswith('application/mercurial'): |
|
15 | 18 | return True |
|
16 | 19 | return False |
|
20 | ||
|
21 | def check_repo_dir(paths): | |
|
22 | repos_path = paths[0][1].split('/') | |
|
23 | if repos_path[-1] in ['*', '**']: | |
|
24 | repos_path = repos_path[:-1] | |
|
25 | if repos_path[0] != '/': | |
|
26 | repos_path[0] = '/' | |
|
27 | if not os.path.isdir(os.path.join(*repos_path)): | |
|
28 | raise Exception('Not a valid repository in %s' % paths[0][1]) | |
|
29 | ||
|
30 | def make_ui(path='hgwebdir.config', checkpaths=True): | |
|
31 | """ | |
|
32 | A funcion that will read python rc files and make an ui from read options | |
|
33 | ||
|
34 | @param path: path to mercurial config file | |
|
35 | """ | |
|
36 | if not os.path.isfile(path): | |
|
37 | logging.error('Unable to read config file %s' % path) | |
|
38 | return False | |
|
39 | #propagated from mercurial documentation | |
|
40 | sections = [ | |
|
41 | 'alias', | |
|
42 | 'auth', | |
|
43 | 'decode/encode', | |
|
44 | 'defaults', | |
|
45 | 'diff', | |
|
46 | 'email', | |
|
47 | 'extensions', | |
|
48 | 'format', | |
|
49 | 'merge-patterns', | |
|
50 | 'merge-tools', | |
|
51 | 'hooks', | |
|
52 | 'http_proxy', | |
|
53 | 'smtp', | |
|
54 | 'patch', | |
|
55 | 'paths', | |
|
56 | 'profiling', | |
|
57 | 'server', | |
|
58 | 'trusted', | |
|
59 | 'ui', | |
|
60 | 'web', | |
|
61 | ] | |
|
62 | ||
|
63 | baseui = ui.ui() | |
|
64 | cfg = config.config() | |
|
65 | cfg.read(path) | |
|
66 | if checkpaths:check_repo_dir(cfg.items('paths')) | |
|
67 | ||
|
68 | for section in sections: | |
|
69 | for k, v in cfg.items(section): | |
|
70 | baseui.setconfig(section, k, v) | |
|
71 | ||
|
72 | return baseui | |
|
73 | ||
|
74 | ||
|
75 |
General Comments 0
You need to be logged in to leave comments.
Login now