Mercurial > kallithea
comparison pylons_app/lib/utils.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 | f24b9a2934cf |
children | 2811259dc12d |
comparison
equal
deleted
inserted
replaced
113:b6e219f3a58d | 114:cc5cf1a93902 |
---|---|
1 from mercurial import ui, config | |
2 import os | |
3 import logging | |
1 | 4 |
2 def get_repo_slug(request): | 5 def get_repo_slug(request): |
3 path_info = request.environ.get('PATH_INFO') | 6 path_info = request.environ.get('PATH_INFO') |
4 uri_lst = path_info.split('/') | 7 uri_lst = path_info.split('/') |
5 repo_name = uri_lst[1] | 8 repo_name = uri_lst[1] |
12 """ | 15 """ |
13 http_accept = environ.get('HTTP_ACCEPT') | 16 http_accept = environ.get('HTTP_ACCEPT') |
14 if http_accept and http_accept.startswith('application/mercurial'): | 17 if http_accept and http_accept.startswith('application/mercurial'): |
15 return True | 18 return True |
16 return False | 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 |