Changeset - 7174ee850baa
[Not reviewed]
beta
0 7 0
Marcin Kuzminski - 13 years ago 2013-03-10 22:53:25
marcin@python-works.com
configurable locking codes.
- this allows changing the default 423 LOCKED code to 2XX codes which don't break the transactions. Insted
it gives users a warning for push.
7 files changed with 59 insertions and 6 deletions:
0 comments (0 inline, 0 general)
development.ini
Show inline comments
 
@@ -156,6 +156,11 @@ instance_id =
 
## handling that. Set this variable to 403 to return HTTPForbidden
 
auth_ret_code =
 

	
 
## locking return code. When repository is locked return this HTTP code. 2XX
 
## codes don't break the transactions while 4XX codes do
 
lock_ret_code = 423
 

	
 

	
 
####################################
 
###        CELERY CONFIG        ####
 
####################################
production.ini
Show inline comments
 
@@ -156,6 +156,11 @@ instance_id =
 
## handling that. Set this variable to 403 to return HTTPForbidden
 
auth_ret_code =
 

	
 
## locking return code. When repository is locked return this HTTP code. 2XX
 
## codes don't break the transactions while 4XX codes do
 
lock_ret_code = 423
 

	
 

	
 
####################################
 
###        CELERY CONFIG        ####
 
####################################
rhodecode/config/deployment.ini_tmpl
Show inline comments
 
@@ -156,6 +156,11 @@ instance_id =
 
## handling that. Set this variable to 403 to return HTTPForbidden
 
auth_ret_code =
 

	
 
## locking return code. When repository is locked return this HTTP code. 2XX
 
## codes don't break the transactions while 4XX codes do
 
lock_ret_code = 423
 

	
 

	
 
####################################
 
###        CELERY CONFIG        ####
 
####################################
rhodecode/lib/exceptions.py
Show inline comments
 
@@ -60,12 +60,17 @@ class StatusChangeOnClosedPullRequestErr
 

	
 
class HTTPLockedRC(HTTPClientError):
 
    """
 
    Special Exception For locked Repos in RhodeCode
 
    Special Exception For locked Repos in RhodeCode, the return code can
 
    be overwritten by _code keyword argument passed into constructors
 
    """
 
    code = 423
 
    title = explanation = 'Repository Locked'
 

	
 
    def __init__(self, reponame, username, *args, **kwargs):
 
        from rhodecode import CONFIG
 
        from rhodecode.lib.utils2 import safe_int
 
        _code = CONFIG.get('lock_ret_code')
 
        self.code = safe_int(_code, self.code)
 
        self.title = self.explanation = ('Repository `%s` locked by '
 
                                         'user `%s`' % (reponame, username))
 
        super(HTTPLockedRC, self).__init__(*args, **kwargs)
rhodecode/lib/hooks.py
Show inline comments
 
@@ -36,7 +36,7 @@ from rhodecode.lib.utils import action_l
 
from rhodecode.lib.vcs.backends.base import EmptyChangeset
 
from rhodecode.lib.compat import json
 
from rhodecode.lib.exceptions import HTTPLockedRC
 
from rhodecode.lib.utils2 import safe_str, datetime_to_time
 
from rhodecode.lib.utils2 import safe_str
 
from rhodecode.model.db import Repository, User
 

	
 

	
 
@@ -113,7 +113,14 @@ def pre_push(ui, repo, **kwargs):
 
    usr = User.get_by_username(username)
 
    if locked_by[0] and usr.user_id != int(locked_by[0]):
 
        locked_by = User.get(locked_by[0]).username
 
        raise HTTPLockedRC(repository, locked_by)
 
        # this exception is interpreted in git/hg middlewares and based
 
        # on that proper return code is server to client
 
        _http_ret = HTTPLockedRC(repository, locked_by)
 
        if str(_http_ret.code).startswith('2'):
 
            #2xx Codes don't raise exceptions
 
            sys.stdout.write(_http_ret.title)
 
        else:
 
            raise _http_ret
 

	
 

	
 
def pre_pull(ui, repo, **kwargs):
 
@@ -139,7 +146,14 @@ def pre_pull(ui, repo, **kwargs):
 

	
 
    if locked_by[0]:
 
        locked_by = User.get(locked_by[0]).username
 
        raise HTTPLockedRC(repository, locked_by)
 
        # this exception is interpreted in git/hg middlewares and based
 
        # on that proper return code is server to client
 
        _http_ret = HTTPLockedRC(repository, locked_by)
 
        if str(_http_ret.code).startswith('2'):
 
            #2xx Codes don't raise exceptions
 
            sys.stdout.write(_http_ret.title)
 
        else:
 
            raise _http_ret
 

	
 

	
 
def log_pull_action(ui, repo, **kwargs):
 
@@ -159,12 +173,14 @@ def log_pull_action(ui, repo, **kwargs):
 
        repository = extras['repository']
 
        scm = extras['scm']
 
        make_lock = extras['make_lock']
 
        locked_by = extras['locked_by']
 
        ip = extras['ip']
 
    elif 'username' in rc_extras:
 
        username = rc_extras['username']
 
        repository = rc_extras['repository']
 
        scm = rc_extras['scm']
 
        make_lock = rc_extras['make_lock']
 
        locked_by = rc_extras['locked_by']
 
        ip = rc_extras['ip']
 
    else:
 
        raise Exception('Missing data in repo.ui and os.environ')
 
@@ -185,6 +201,12 @@ def log_pull_action(ui, repo, **kwargs):
 
        #msg = 'Made lock on repo `%s`' % repository
 
        #sys.stdout.write(msg)
 

	
 
    if locked_by[0]:
 
        locked_by = User.get(locked_by[0]).username
 
        _http_ret = HTTPLockedRC(repository, locked_by)
 
        if str(_http_ret.code).startswith('2'):
 
            #2xx Codes don't raise exceptions
 
            sys.stdout.write(_http_ret.title)
 
    return 0
 

	
 

	
 
@@ -207,12 +229,14 @@ def log_push_action(ui, repo, **kwargs):
 
        repository = extras['repository']
 
        scm = extras['scm']
 
        make_lock = extras['make_lock']
 
        locked_by = extras['locked_by']
 
        action = extras['action']
 
    elif 'username' in rc_extras:
 
        username = rc_extras['username']
 
        repository = rc_extras['repository']
 
        scm = rc_extras['scm']
 
        make_lock = rc_extras['make_lock']
 
        locked_by = rc_extras['locked_by']
 
        action = extras['action']
 
    else:
 
        raise Exception('Missing data in repo.ui and os.environ')
 
@@ -257,6 +281,13 @@ def log_push_action(ui, repo, **kwargs):
 
        msg = 'Released lock on repo `%s`\n' % repository
 
        sys.stdout.write(msg)
 

	
 
    if locked_by[0]:
 
        locked_by = User.get(locked_by[0]).username
 
        _http_ret = HTTPLockedRC(repository, locked_by)
 
        if str(_http_ret.code).startswith('2'):
 
            #2xx Codes don't raise exceptions
 
            sys.stdout.write(_http_ret.title)
 

	
 
    return 0
 

	
 

	
rhodecode/lib/middleware/simplegit.py
Show inline comments
 
@@ -234,7 +234,8 @@ class SimpleGit(BaseVCSController):
 
            app = self.__make_app(repo_name, repo_path, extras)
 
            return app(environ, start_response)
 
        except HTTPLockedRC, e:
 
            log.debug('Repository LOCKED ret code 423!')
 
            _code = CONFIG.get('lock_ret_code')
 
            log.debug('Repository LOCKED ret code %s!' % (_code))
 
            return e(environ, start_response)
 
        except Exception:
 
            log.error(traceback.format_exc())
rhodecode/lib/middleware/simplehg.py
Show inline comments
 
@@ -199,7 +199,8 @@ class SimpleHg(BaseVCSController):
 
            if str(e).find('not found') != -1:
 
                return HTTPNotFound()(environ, start_response)
 
        except HTTPLockedRC, e:
 
            log.debug('Repository LOCKED ret code 423!')
 
            _code = CONFIG.get('lock_ret_code')
 
            log.debug('Repository LOCKED ret code %s!' % (_code))
 
            return e(environ, start_response)
 
        except Exception:
 
            log.error(traceback.format_exc())
0 comments (0 inline, 0 general)