Changeset - 586f80f48113
[Not reviewed]
default
0 5 1
domruf - 8 years ago 2017-11-25 10:20:23
dominikruf@gmail.com
Grafted from: 9b5a5202f647
hooks: rename hooks to reflect what they are doing

The names of our hooks should reflect what they are doing.
So, since pre_push and pre_pull only handle the locking, rename
pre_push->push_lock_handling and pre_pull->pull_lock_handling.

This imply a database migration step which must be run as described in the
upgrade documentation.

Also rename db.Ui class variables.
6 files changed with 84 insertions and 23 deletions:
0 comments (0 inline, 0 general)
kallithea/alembic/versions/a020f7044fd6_rename_hooks.py
Show inline comments
 
new file 100644
 
# 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, either version 3 of the License, or
 
# (at your option) any later version.
 
#
 
# This program is distributed in the hope that it will be useful,
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
# 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, see <http://www.gnu.org/licenses/>.
 

	
 
"""rename hooks
 

	
 
Revision ID: a020f7044fd6
 
Revises: 9358dc3d6828
 
Create Date: 2017-11-24 13:35:14.374000
 

	
 
"""
 

	
 
# The following opaque hexadecimal identifiers ("revisions") are used
 
# by Alembic to track this migration script and its relations to others.
 
revision = 'a020f7044fd6'
 
down_revision = '9358dc3d6828'
 
branch_labels = None
 
depends_on = None
 

	
 
from alembic import op
 
from kallithea.model.db import Ui
 
from sqlalchemy import Table, MetaData
 

	
 
meta = MetaData()
 

	
 

	
 
def upgrade():
 
    meta.bind = op.get_bind()
 
    ui = Table(Ui.__tablename__, meta, autoload=True)
 

	
 
    ui.update(values={
 
        'ui_key': 'prechangegroup.push_lock_handling',
 
        'ui_value': 'python:kallithea.lib.hooks.push_lock_handling',
 
    }).where(ui.c.ui_key == 'prechangegroup.pre_push').execute()
 
    ui.update(values={
 
        'ui_key': 'preoutgoing.pull_lock_handling',
 
        'ui_value': 'python:kallithea.lib.hooks.pull_lock_handling',
 
    }).where(ui.c.ui_key == 'preoutgoing.pre_pull').execute()
 

	
 

	
 
def downgrade():
 
    meta.bind = op.get_bind()
 
    ui = Table(Ui.__tablename__, meta, autoload=True)
 

	
 
    ui.update(values={
 
        'ui_key': 'prechangegroup.pre_push',
 
        'ui_value': 'python:kallithea.lib.hooks.pre_push',
 
    }).where(ui.c.ui_key == 'prechangegroup.push_lock_handling').execute()
 
    ui.update(values={
 
        'ui_key': 'preoutgoing.pre_pull',
 
        'ui_value': 'python:kallithea.lib.hooks.pre_pull',
 
    }).where(ui.c.ui_key == 'preoutgoing.pull_lock_handling').execute()
kallithea/controllers/admin/settings.py
Show inline comments
 
@@ -109,10 +109,10 @@ class SettingsController(BaseController)
 
                sett = Ui.get_by_key('hooks', Ui.HOOK_REPO_SIZE)
 
                sett.ui_active = form_result['hooks_changegroup_repo_size']
 

	
 
                sett = Ui.get_by_key('hooks', Ui.HOOK_PUSH)
 
                sett = Ui.get_by_key('hooks', Ui.HOOK_PUSH_LOG)
 
                sett.ui_active = form_result['hooks_changegroup_push_logger']
 

	
 
                sett = Ui.get_by_key('hooks', Ui.HOOK_PULL)
 
                sett = Ui.get_by_key('hooks', Ui.HOOK_PULL_LOG)
 
                sett.ui_active = form_result['hooks_outgoing_pull_logger']
 

	
 
                ## EXTENSIONS
kallithea/lib/db_manage.py
Show inline comments
 
@@ -257,26 +257,26 @@ class DbManage(object):
 

	
 
        hooks3 = Ui()
 
        hooks3.ui_section = 'hooks'
 
        hooks3.ui_key = Ui.HOOK_PUSH
 
        hooks3.ui_key = Ui.HOOK_PUSH_LOG
 
        hooks3.ui_value = 'python:kallithea.lib.hooks.log_push_action'
 
        self.sa.add(hooks3)
 

	
 
        hooks4 = Ui()
 
        hooks4.ui_section = 'hooks'
 
        hooks4.ui_key = Ui.HOOK_PRE_PUSH
 
        hooks4.ui_value = 'python:kallithea.lib.hooks.pre_push'
 
        hooks4.ui_key = Ui.HOOK_PUSH_LOCK
 
        hooks4.ui_value = 'python:kallithea.lib.hooks.push_lock_handling'
 
        self.sa.add(hooks4)
 

	
 
        hooks5 = Ui()
 
        hooks5.ui_section = 'hooks'
 
        hooks5.ui_key = Ui.HOOK_PULL
 
        hooks5.ui_key = Ui.HOOK_PULL_LOG
 
        hooks5.ui_value = 'python:kallithea.lib.hooks.log_pull_action'
 
        self.sa.add(hooks5)
 

	
 
        hooks6 = Ui()
 
        hooks6.ui_section = 'hooks'
 
        hooks6.ui_key = Ui.HOOK_PRE_PULL
 
        hooks6.ui_value = 'python:kallithea.lib.hooks.pre_pull'
 
        hooks6.ui_key = Ui.HOOK_PULL_LOCK
 
        hooks6.ui_value = 'python:kallithea.lib.hooks.pull_lock_handling'
 
        self.sa.add(hooks6)
 

	
 
        # enable largefiles
kallithea/lib/hooks.py
Show inline comments
 
@@ -86,7 +86,7 @@ def repo_size(ui, repo, hooktype=None, *
 
    ui.status(msg)
 

	
 

	
 
def pre_push(ui, repo, **kwargs):
 
def push_lock_handling(ui, repo, **kwargs):
 
    # pre push function, currently used to ban pushing when
 
    # repository is locked
 
    ex = _extract_extras()
 
@@ -104,7 +104,7 @@ def pre_push(ui, repo, **kwargs):
 
            raise _http_ret
 

	
 

	
 
def pre_pull(ui, repo, **kwargs):
 
def pull_lock_handling(ui, repo, **kwargs):
 
    # pre pull function ...
 
    ex = _extract_extras()
 
    if ex.locked_by[0]:
 
@@ -420,10 +420,10 @@ def handle_git_receive(repo_path, git_st
 
        repo = repo.scm_instance_no_cache()
 

	
 
    if hook_type == 'pre':
 
        pre_push(baseui, repo)
 
        push_lock_handling(baseui, repo)
 

	
 
    # if push hook is enabled via web interface
 
    elif hook_type == 'post' and _hooks.get(Ui.HOOK_PUSH):
 
    elif hook_type == 'post' and _hooks.get(Ui.HOOK_PUSH_LOG):
 
        rev_data = []
 
        for l in git_stdin_lines:
 
            old_rev, new_rev, ref = l.strip().split(' ')
kallithea/lib/middleware/simplegit.py
Show inline comments
 
@@ -43,7 +43,7 @@ from kallithea.lib.utils2 import safe_st
 
from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback, check_locking_state
 
from kallithea.lib.utils import make_ui, is_valid_repo
 
from kallithea.lib.exceptions import HTTPLockedRC
 
from kallithea.lib.hooks import pre_pull
 
from kallithea.lib.hooks import pull_lock_handling
 
from kallithea.lib import auth_modules
 

	
 
log = logging.getLogger(__name__)
 
@@ -222,8 +222,8 @@ class SimpleGit(BaseVCSController):
 
        _hooks = dict(baseui.configitems('hooks')) or {}
 
        if action == 'pull':
 
            # stupid git, emulate pre-pull hook !
 
            pre_pull(ui=baseui, repo=_repo._repo)
 
        if action == 'pull' and _hooks.get(Ui.HOOK_PULL):
 
            pull_lock_handling(ui=baseui, repo=_repo._repo)
 
        if action == 'pull' and _hooks.get(Ui.HOOK_PULL_LOG):
 
            log_pull_action(ui=baseui, repo=_repo._repo)
 

	
 
    def __inject_extras(self, repo_path, baseui, extras=None):
kallithea/model/db.py
Show inline comments
 
@@ -351,10 +351,10 @@ class Ui(Base, BaseDbModel):
 

	
 
    HOOK_UPDATE = 'changegroup.update'
 
    HOOK_REPO_SIZE = 'changegroup.repo_size'
 
    HOOK_PUSH = 'changegroup.push_logger'
 
    HOOK_PRE_PUSH = 'prechangegroup.pre_push'
 
    HOOK_PULL = 'outgoing.pull_logger'
 
    HOOK_PRE_PULL = 'preoutgoing.pre_pull'
 
    HOOK_PUSH_LOG = 'changegroup.push_logger'
 
    HOOK_PUSH_LOCK = 'prechangegroup.push_lock_handling'
 
    HOOK_PULL_LOG = 'outgoing.pull_logger'
 
    HOOK_PULL_LOCK = 'preoutgoing.pull_lock_handling'
 

	
 
    ui_id = Column(Integer(), primary_key=True)
 
    ui_section = Column(String(255), nullable=False)
 
@@ -380,8 +380,8 @@ class Ui(Base, BaseDbModel):
 
    def get_builtin_hooks(cls):
 
        q = cls.query()
 
        q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
 
                                     cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
 
                                     cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
 
                                     cls.HOOK_PUSH_LOG, cls.HOOK_PUSH_LOCK,
 
                                     cls.HOOK_PULL_LOG, cls.HOOK_PULL_LOCK]))
 
        q = q.filter(cls.ui_section == 'hooks')
 
        return q.all()
 

	
 
@@ -389,8 +389,8 @@ class Ui(Base, BaseDbModel):
 
    def get_custom_hooks(cls):
 
        q = cls.query()
 
        q = q.filter(~cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
 
                                      cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
 
                                      cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
 
                                      cls.HOOK_PUSH_LOG, cls.HOOK_PUSH_LOCK,
 
                                      cls.HOOK_PULL_LOG, cls.HOOK_PULL_LOCK]))
 
        q = q.filter(cls.ui_section == 'hooks')
 
        return q.all()
 

	
0 comments (0 inline, 0 general)