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