Mercurial > kallithea
changeset 1505:bb6ba7442293 beta
Fixed methods for checking if path in routes is a repo
added method for checking if path in route is a repos_group
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sat, 01 Oct 2011 19:05:47 +0300 |
parents | ed3254ac279b |
children | 7865043e4ca9 |
files | rhodecode/config/routing.py rhodecode/lib/utils.py rhodecode/model/repo.py |
diffstat | 3 files changed, 61 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/config/routing.py Sat Oct 01 16:44:54 2011 +0300 +++ b/rhodecode/config/routing.py Sat Oct 01 19:05:47 2011 +0300 @@ -7,7 +7,7 @@ """ from __future__ import with_statement from routes import Mapper -from rhodecode.lib.utils import check_repo_fast as cr + # prefix for non repository related links needs to be prefixed with `/` ADMIN_PREFIX = '/_admin' @@ -19,23 +19,36 @@ always_scan=config['debug']) rmap.minimization = False rmap.explicit = False - + + from rhodecode.lib.utils import check_repo_fast + from rhodecode.lib.utils import check_repos_group_fast + def check_repo(environ, match_dict): """ check for valid repository for proper 404 handling + :param environ: :param match_dict: """ + repo_name = match_dict.get('repo_name') - return not cr(repo_name, config['base_path']) + return check_repo_fast(repo_name, config['base_path']) + + def check_group(environ, match_dict): + """ + check for valid repositories group for proper 404 handling + + :param environ: + :param match_dict: + """ + repos_group_name = match_dict.get('group_name') + + return check_repos_group_fast(repos_group_name, config['base_path']) def check_int(environ, match_dict): return match_dict.get('id').isdigit() - - - # The ErrorController route (handles 404/500 error pages); it should # likely stay at the top, ensuring it can always be resolved rmap.connect('/error/{action}', controller='error') @@ -319,6 +332,14 @@ #========================================================================== # REPOSITORY ROUTES #========================================================================== + rmap.connect('summary_home', '/{repo_name:.*}', + controller='summary', + conditions=dict(function=check_repo)) + +# rmap.connect('repo_group_home', '/{group_name:.*}', +# controller='admin/repos_groups',action="show_by_name", +# conditions=dict(function=check_group)) + rmap.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', controller='changeset', revision='tip', conditions=dict(function=check_repo)) @@ -328,9 +349,6 @@ controller='changeset', action='raw_changeset', revision='tip', conditions=dict(function=check_repo)) - rmap.connect('summary_home', '/{repo_name:.*}', - controller='summary', conditions=dict(function=check_repo)) - rmap.connect('summary_home', '/{repo_name:.*}/summary', controller='summary', conditions=dict(function=check_repo))
--- a/rhodecode/lib/utils.py Sat Oct 01 16:44:54 2011 +0300 +++ b/rhodecode/lib/utils.py Sat Oct 01 19:05:47 2011 +0300 @@ -33,23 +33,21 @@ from paste.script.command import Command, BadCommand -from UserDict import DictMixin - -from mercurial import ui, config, hg -from mercurial.error import RepoError +from mercurial import ui, config from webhelpers.text import collapse, remove_formatting, strip_tags +from vcs import get_backend from vcs.backends.base import BaseChangeset from vcs.utils.lazy import LazyProperty -from vcs import get_backend +from vcs.utils.helpers import get_scm +from vcs.exceptions import VCSError from rhodecode.model import meta from rhodecode.model.caching_query import FromCache from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog, Group, \ RhodeCodeSettings from rhodecode.model.repo import RepoModel -from rhodecode.model.user import UserModel log = logging.getLogger(__name__) @@ -111,11 +109,10 @@ sa = meta.Session() try: - um = UserModel() if hasattr(user, 'user_id'): user_obj = user elif isinstance(user, basestring): - user_obj = um.get_by_username(user, cache=False) + user_obj = User.by_username(user, cache=False) else: raise Exception('You have to provide user object or username') @@ -185,36 +182,39 @@ def check_repo_fast(repo_name, base_path): """ - Check given path for existence of directory + Returns True if given path is a valid repository False otherwise :param repo_name: :param base_path: - :return False: if this directory is present + :return True: if given path is a valid repository """ - if os.path.isdir(os.path.join(base_path, repo_name)): - return False - return True - - -def check_repo(repo_name, base_path, verify=True): - - repo_path = os.path.join(base_path, repo_name) - + full_path = os.path.join(base_path, repo_name) + try: - if not check_repo_fast(repo_name, base_path): - return False - r = hg.repository(ui.ui(), repo_path) - if verify: - hg.verify(r) - #here we hnow that repo exists it was verified - log.info('%s repo is already created', repo_name) + get_scm(full_path) + return True + except VCSError: return False - except RepoError: - #it means that there is no valid repo there... - log.info('%s repo is free for creation', repo_name) + +def check_repos_group_fast(repos_group_name, base_path): + """ + Returns True if given path is a repos group False otherwise + + :param repo_name: + :param base_path: + """ + full_path = os.path.join(base_path, repos_group_name) + + # check if it's not a repo + if check_repo_fast(repos_group_name, base_path): + return False + + # check if it's a valid path + if os.path.isdir(full_path): return True - - + + return False + def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): while True: ok = raw_input(prompt)
--- a/rhodecode/model/repo.py Sat Oct 01 16:44:54 2011 +0300 +++ b/rhodecode/model/repo.py Sat Oct 01 19:05:47 2011 +0300 @@ -301,8 +301,8 @@ :param parent_id: :param clone_uri: """ - from rhodecode.lib.utils import check_repo - + from rhodecode.lib.utils import check_repo_fast + if new_parent_id: paths = Group.get(new_parent_id).full_path.split(Group.url_sep()) new_parent_path = os.sep.join(paths) @@ -312,7 +312,7 @@ repo_path = os.path.join(*map(lambda x:safe_str(x), [self.repos_path, new_parent_path, repo_name])) - if check_repo(repo_path, self.repos_path): + if check_repo_fast(repo_path, self.repos_path) is False: log.info('creating repo %s in %s @ %s', repo_name, repo_path, clone_uri) backend = get_backend(alias)