comparison pylons_app/lib/middleware/simplehg.py @ 385:eda5f01de3c4

fixes #20 hg middleware breaks ui() instance when repository has hgrc file. hgrc file now updates application ui instance with only those section that are present.
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 05 Aug 2010 01:21:44 +0200
parents 55377fdc1fc6
children b27d32cb3157
comparison
equal deleted inserted replaced
384:c8fc57b92a60 385:eda5f01de3c4
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # encoding: utf-8 2 # encoding: utf-8
3 # middleware to handle mercurial api calls 3 # middleware to handle mercurial api calls
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> 4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 5 #
6 # This program is free software; you can redistribute it and/or 6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License 7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2 8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license. 9 # of the License or (at your opinion) any later version of the license.
10 # 10 #
15 # 15 #
16 # You should have received a copy of the GNU General Public License 16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software 17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA. 19 # MA 02110-1301, USA.
20
21 """
22 Created on 2010-04-28
23
24 @author: marcink
25 SimpleHG middleware for handling mercurial protocol request (push/clone etc.)
26 It's implemented with basic auth function
27 """
28 from datetime import datetime 20 from datetime import datetime
29 from itertools import chain 21 from itertools import chain
30 from mercurial.error import RepoError 22 from mercurial.error import RepoError
31 from mercurial.hgweb import hgweb 23 from mercurial.hgweb import hgweb
32 from mercurial.hgweb.request import wsgiapplication 24 from mercurial.hgweb.request import wsgiapplication
33 from paste.auth.basic import AuthBasicAuthenticator 25 from paste.auth.basic import AuthBasicAuthenticator
34 from paste.httpheaders import REMOTE_USER, AUTH_TYPE 26 from paste.httpheaders import REMOTE_USER, AUTH_TYPE
35 from pylons_app.lib.auth import authfunc, HasPermissionAnyMiddleware, \ 27 from pylons_app.lib.auth import authfunc, HasPermissionAnyMiddleware, \
36 get_user_cached 28 get_user_cached
37 from pylons_app.lib.utils import is_mercurial, make_ui, invalidate_cache, \ 29 from pylons_app.lib.utils import is_mercurial, make_ui, invalidate_cache, \
38 check_repo_fast 30 check_repo_fast, ui_sections
39 from pylons_app.model import meta 31 from pylons_app.model import meta
40 from pylons_app.model.db import UserLog, User 32 from pylons_app.model.db import UserLog, User
41 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError 33 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
42 import logging 34 import logging
43 import os 35 import os
44 import pylons_app.lib.helpers as h 36 import pylons_app.lib.helpers as h
45 import traceback 37 import traceback
38
39 """
40 Created on 2010-04-28
41
42 @author: marcink
43 SimpleHG middleware for handling mercurial protocol request (push/clone etc.)
44 It's implemented with basic auth function
45 """
46 46
47 log = logging.getLogger(__name__) 47 log = logging.getLogger(__name__)
48 48
49 class SimpleHg(object): 49 class SimpleHg(object):
50 50
224 hgserve.repo.ui = self.baseui 224 hgserve.repo.ui = self.baseui
225 225
226 hgrc = os.path.join(self.repo_path, '.hg', 'hgrc') 226 hgrc = os.path.join(self.repo_path, '.hg', 'hgrc')
227 repoui = make_ui('file', hgrc, False) 227 repoui = make_ui('file', hgrc, False)
228 228
229
229 if repoui: 230 if repoui:
230 #set the repository based config 231 #overwrite our ui instance with the section from hgrc file
231 hgserve.repo.ui = repoui 232 for section in ui_sections:
233 for k, v in repoui.configitems(section):
234 hgserve.repo.ui.setconfig(section, k, v)
232 235
233 return hgserve 236 return hgserve
237
238
239
240
241
242
243
244
245
246
247
248
249
250