##// END OF EJS Templates
Fixed methods for checking if path in routes is a repo...
marcink -
r1505:bb6ba744 beta
parent child Browse files
Show More
@@ -7,7 +7,7 b' refer to the routes manual at http://rou'
7 7 """
8 8 from __future__ import with_statement
9 9 from routes import Mapper
10 from rhodecode.lib.utils import check_repo_fast as cr
10
11 11
12 12 # prefix for non repository related links needs to be prefixed with `/`
13 13 ADMIN_PREFIX = '/_admin'
@@ -19,23 +19,36 b' def make_map(config):'
19 19 always_scan=config['debug'])
20 20 rmap.minimization = False
21 21 rmap.explicit = False
22
22
23 from rhodecode.lib.utils import check_repo_fast
24 from rhodecode.lib.utils import check_repos_group_fast
25
23 26 def check_repo(environ, match_dict):
24 27 """
25 28 check for valid repository for proper 404 handling
29
26 30 :param environ:
27 31 :param match_dict:
28 32 """
33
29 34 repo_name = match_dict.get('repo_name')
30 return not cr(repo_name, config['base_path'])
35 return check_repo_fast(repo_name, config['base_path'])
36
37 def check_group(environ, match_dict):
38 """
39 check for valid repositories group for proper 404 handling
40
41 :param environ:
42 :param match_dict:
43 """
44 repos_group_name = match_dict.get('group_name')
45
46 return check_repos_group_fast(repos_group_name, config['base_path'])
31 47
32 48
33 49 def check_int(environ, match_dict):
34 50 return match_dict.get('id').isdigit()
35 51
36
37
38
39 52 # The ErrorController route (handles 404/500 error pages); it should
40 53 # likely stay at the top, ensuring it can always be resolved
41 54 rmap.connect('/error/{action}', controller='error')
@@ -319,6 +332,14 b' def make_map(config):'
319 332 #==========================================================================
320 333 # REPOSITORY ROUTES
321 334 #==========================================================================
335 rmap.connect('summary_home', '/{repo_name:.*}',
336 controller='summary',
337 conditions=dict(function=check_repo))
338
339 # rmap.connect('repo_group_home', '/{group_name:.*}',
340 # controller='admin/repos_groups',action="show_by_name",
341 # conditions=dict(function=check_group))
342
322 343 rmap.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}',
323 344 controller='changeset', revision='tip',
324 345 conditions=dict(function=check_repo))
@@ -328,9 +349,6 b' def make_map(config):'
328 349 controller='changeset', action='raw_changeset',
329 350 revision='tip', conditions=dict(function=check_repo))
330 351
331 rmap.connect('summary_home', '/{repo_name:.*}',
332 controller='summary', conditions=dict(function=check_repo))
333
334 352 rmap.connect('summary_home', '/{repo_name:.*}/summary',
335 353 controller='summary', conditions=dict(function=check_repo))
336 354
@@ -33,23 +33,21 b' from os.path import dirname as dn, join '
33 33
34 34 from paste.script.command import Command, BadCommand
35 35
36 from UserDict import DictMixin
37
38 from mercurial import ui, config, hg
39 from mercurial.error import RepoError
36 from mercurial import ui, config
40 37
41 38 from webhelpers.text import collapse, remove_formatting, strip_tags
42 39
40 from vcs import get_backend
43 41 from vcs.backends.base import BaseChangeset
44 42 from vcs.utils.lazy import LazyProperty
45 from vcs import get_backend
43 from vcs.utils.helpers import get_scm
44 from vcs.exceptions import VCSError
46 45
47 46 from rhodecode.model import meta
48 47 from rhodecode.model.caching_query import FromCache
49 48 from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog, Group, \
50 49 RhodeCodeSettings
51 50 from rhodecode.model.repo import RepoModel
52 from rhodecode.model.user import UserModel
53 51
54 52 log = logging.getLogger(__name__)
55 53
@@ -111,11 +109,10 b' def action_logger(user, action, repo, ip'
111 109 sa = meta.Session()
112 110
113 111 try:
114 um = UserModel()
115 112 if hasattr(user, 'user_id'):
116 113 user_obj = user
117 114 elif isinstance(user, basestring):
118 user_obj = um.get_by_username(user, cache=False)
115 user_obj = User.by_username(user, cache=False)
119 116 else:
120 117 raise Exception('You have to provide user object or username')
121 118
@@ -185,36 +182,39 b' def get_repos(path, recursive=False):'
185 182
186 183 def check_repo_fast(repo_name, base_path):
187 184 """
188 Check given path for existence of directory
185 Returns True if given path is a valid repository False otherwise
189 186 :param repo_name:
190 187 :param base_path:
191 188
192 :return False: if this directory is present
189 :return True: if given path is a valid repository
193 190 """
194 if os.path.isdir(os.path.join(base_path, repo_name)):
195 return False
196 return True
197
198
199 def check_repo(repo_name, base_path, verify=True):
200
201 repo_path = os.path.join(base_path, repo_name)
202
191 full_path = os.path.join(base_path, repo_name)
192
203 193 try:
204 if not check_repo_fast(repo_name, base_path):
205 return False
206 r = hg.repository(ui.ui(), repo_path)
207 if verify:
208 hg.verify(r)
209 #here we hnow that repo exists it was verified
210 log.info('%s repo is already created', repo_name)
194 get_scm(full_path)
195 return True
196 except VCSError:
211 197 return False
212 except RepoError:
213 #it means that there is no valid repo there...
214 log.info('%s repo is free for creation', repo_name)
198
199 def check_repos_group_fast(repos_group_name, base_path):
200 """
201 Returns True if given path is a repos group False otherwise
202
203 :param repo_name:
204 :param base_path:
205 """
206 full_path = os.path.join(base_path, repos_group_name)
207
208 # check if it's not a repo
209 if check_repo_fast(repos_group_name, base_path):
210 return False
211
212 # check if it's a valid path
213 if os.path.isdir(full_path):
215 214 return True
216
217
215
216 return False
217
218 218 def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
219 219 while True:
220 220 ok = raw_input(prompt)
@@ -301,8 +301,8 b' class RepoModel(BaseModel):'
301 301 :param parent_id:
302 302 :param clone_uri:
303 303 """
304 from rhodecode.lib.utils import check_repo
305
304 from rhodecode.lib.utils import check_repo_fast
305
306 306 if new_parent_id:
307 307 paths = Group.get(new_parent_id).full_path.split(Group.url_sep())
308 308 new_parent_path = os.sep.join(paths)
@@ -312,7 +312,7 b' class RepoModel(BaseModel):'
312 312 repo_path = os.path.join(*map(lambda x:safe_str(x),
313 313 [self.repos_path, new_parent_path, repo_name]))
314 314
315 if check_repo(repo_path, self.repos_path):
315 if check_repo_fast(repo_path, self.repos_path) is False:
316 316 log.info('creating repo %s in %s @ %s', repo_name, repo_path,
317 317 clone_uri)
318 318 backend = get_backend(alias)
General Comments 0
You need to be logged in to leave comments. Login now