comparison pylons_app/lib/middleware/simplehg.py @ 392:b27d32cb3157

Implemented hooks system, Added repo size hook, and active flag on ui settings in the database to able to toggle them.
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 06 Aug 2010 02:03:22 +0200
parents eda5f01de3c4
children 946d8a680a1d
comparison
equal deleted inserted replaced
391:a9814a642e11 392:b27d32cb3157
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 Created on 2010-04-28
22
23 @author: marcink
24 SimpleHG middleware for handling mercurial protocol request (push/clone etc.)
25 It's implemented with basic auth function
26 """
20 from datetime import datetime 27 from datetime import datetime
21 from itertools import chain 28 from itertools import chain
22 from mercurial.error import RepoError 29 from mercurial.error import RepoError
23 from mercurial.hgweb import hgweb 30 from mercurial.hgweb import hgweb
24 from mercurial.hgweb.request import wsgiapplication 31 from mercurial.hgweb.request import wsgiapplication
33 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError 40 from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError
34 import logging 41 import logging
35 import os 42 import os
36 import pylons_app.lib.helpers as h 43 import pylons_app.lib.helpers as h
37 import traceback 44 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 45
47 log = logging.getLogger(__name__) 46 log = logging.getLogger(__name__)
48 47
49 class SimpleHg(object): 48 class SimpleHg(object):
50 49
161 return environ.get('REMOTE_USER') 160 return environ.get('REMOTE_USER')
162 161
163 def __get_user(self, username): 162 def __get_user(self, username):
164 return get_user_cached(username) 163 return get_user_cached(username)
165 164
166
167
168 def __get_size(self, repo_path, content_size):
169 size = int(content_size)
170 for path, dirs, files in os.walk(repo_path):
171 if path.find('.hg') == -1:
172 for f in files:
173 size += os.path.getsize(os.path.join(path, f))
174 return size
175 return h.format_byte_size(size)
176
177 def __get_action(self, environ): 165 def __get_action(self, environ):
178 """ 166 """
179 Maps mercurial request commands into a pull or push command. 167 Maps mercurial request commands into a pull or push command.
180 @param environ: 168 @param environ:
181 """ 169 """