Changeset - c52e88b57bf4
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 15 years ago 2010-11-25 21:57:25
marcin@python-works.com
rolled back to make transient since got some exceptions on expunge
import fixups
1 file changed with 39 insertions and 24 deletions:
0 comments (0 inline, 0 general)
rhodecode/model/scm.py
Show inline comments
 
#!/usr/bin/env python
 
# encoding: utf-8
 
# Model for RhodeCode
 
# Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
 
# 
 
# -*- coding: utf-8 -*-
 
"""
 
    package.rhodecode.model.scm
 
    ~~~~~~~~~~~~~~
 

	
 
    scm model for RhodeCode 
 
    :created_on: Apr 9, 2010
 
    :author: marcink
 
    :copyright: (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>    
 
    :license: GPLv3, see COPYING for more details.
 
"""
 
# This program is free software; you can redistribute it and/or
 
# modify it under the terms of the GNU General Public License
 
# as published by the Free Software Foundation; version 2
 
# of the License or (at your opinion) any later version of the license.
 
# 
 
# This program is distributed in the hope that it will be useful,
 
@@ -14,49 +20,49 @@
 
# GNU General Public License for more details.
 
# 
 
# You should have received a copy of the GNU General Public License
 
# along with this program; if not, write to the Free Software
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 
# MA  02110-1301, USA.
 
"""
 
Created on April 9, 2010
 
Model for RhodeCode
 
@author: marcink
 
"""
 

	
 
import os
 
import time
 
import traceback
 
import logging
 

	
 
from vcs import get_backend
 
from vcs.utils.helpers import get_scm
 
from vcs.exceptions import RepositoryError, VCSError
 
from vcs.utils.lazy import LazyProperty
 

	
 
from mercurial import ui
 

	
 
from beaker.cache import cache_region, region_invalidate
 
from mercurial import ui
 

	
 
from rhodecode import BACKENDS
 
from rhodecode.lib import helpers as h
 
from rhodecode.lib.auth import HasRepoPermissionAny
 
from rhodecode.lib.utils import get_repos, make_ui, action_logger
 
from rhodecode.model import BaseModel
 
from rhodecode.model.db import Repository, User, RhodeCodeUi, CacheInvalidation, \
 
    UserFollowing
 
from rhodecode.model.caching_query import FromCache
 

	
 
from sqlalchemy.orm import joinedload
 
from sqlalchemy.orm.session import make_transient
 
from vcs import get_backend
 
from vcs.utils.helpers import get_scm
 
from vcs.exceptions import RepositoryError, VCSError
 
from vcs.utils.lazy import LazyProperty
 
import traceback
 
import logging
 
import os
 
import time
 

	
 
log = logging.getLogger(__name__)
 

	
 

	
 
class UserTemp(object):
 
    def __init__(self, user_id):
 
        self.user_id = user_id
 

	
 
class RepoTemp(object):
 
    def __init__(self, repo_id):
 
        self.repo_id = repo_id
 

	
 

	
 
class ScmModel(BaseModel):
 
    """
 
    Mercurial Model
 
    """
 

	
 
    @LazyProperty
 
@@ -65,20 +71,19 @@ class ScmModel(BaseModel):
 
        Get's the repositories root path from database
 
        """
 
        q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one()
 

	
 
        return q.ui_value
 

	
 
    def repo_scan(self, repos_path, baseui, initial=False):
 
    def repo_scan(self, repos_path, baseui):
 
        """
 
        Listing of repositories in given path. This path should not be a 
 
        repository itself. Return a dictionary of repository objects
 
        
 
        :param repos_path: path to directory containing repositories
 
        :param baseui
 
        :param initial: initial scan
 
        """
 
        log.info('scanning for repositories in %s', repos_path)
 

	
 
        if not isinstance(baseui, ui.ui):
 
            baseui = make_ui('db')
 
        repos_list = {}
 
@@ -153,20 +158,26 @@ class ScmModel(BaseModel):
 
        :param repo_name:
 
        """
 
        if not HasRepoPermissionAny('repository.read', 'repository.write',
 
                            'repository.admin')(repo_name, 'get repo check'):
 
            return
 

	
 

	
 
        @cache_region('long_term')
 
        def _get_repo(repo_name):
 

	
 
            repo_path = os.path.join(self.repos_path, repo_name)
 

	
 
            try:
 
            alias = get_scm(repo_path)[0]
 

	
 
            log.debug('Creating instance of %s repository', alias)
 
            backend = get_backend(alias)
 
            except VCSError:
 
                log.error(traceback.format_exc())
 
                return
 

	
 
            #TODO: get the baseui from somewhere for this
 
            if alias == 'hg':
 
                from pylons import app_globals as g
 
                repo = backend(repo_path, create=False, baseui=g.baseui)
 
                #skip hidden web repository
 
@@ -178,13 +189,17 @@ class ScmModel(BaseModel):
 
            dbrepo = self.sa.query(Repository)\
 
                .options(joinedload(Repository.fork))\
 
                .options(joinedload(Repository.user))\
 
                .filter(Repository.repo_name == repo_name)\
 
                .scalar()
 

	
 
            self.sa.expunge(dbrepo)
 
            make_transient(dbrepo)
 
            if dbrepo.user:
 
                make_transient(dbrepo.user)
 
            if dbrepo.fork:
 
                make_transient(dbrepo.fork)
 

	
 
            repo.dbrepo = dbrepo
 
            return repo
 

	
 
        pre_invalidate = True
 
        if invalidation_list:
0 comments (0 inline, 0 general)