Blame progit/hooks/__init__.py

Pierre-Yves Chibon a3add0
#-*- coding: utf-8 -*-
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon a3add0
"""
Pierre-Yves Chibon a3add0
 (c) 2014 - Copyright Red Hat Inc
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon a3add0
 Authors:
Pierre-Yves Chibon a3add0
   Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon a3add0
"""
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon 3976d7
import os
Pierre-Yves Chibon c1b435
import shutil
Pierre-Yves Chibon 3976d7
Pierre-Yves Chibon 3976d7
from progit import APP
Pierre-Yves Chibon 3976d7
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon a3add0
class BaseHook(object):
Pierre-Yves Chibon a3add0
    ''' Base class for progit's hooks. '''
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon a3add0
    name = None
Pierre-Yves Chibon a3add0
    form = None
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon a3f816
    @classmethod
Pierre-Yves Chibon 3976d7
    def set_up(cls, project):
Pierre-Yves Chibon 3976d7
        ''' Install the generic post-receive hook that allow us to call
Pierre-Yves Chibon 3976d7
        multiple post-receive hooks as set per plugin.
Pierre-Yves Chibon 3976d7
        '''
Pierre-Yves Chibon 3976d7
        repopath = os.path.join(APP.config['GIT_FOLDER'], project.path)
Pierre-Yves Chibon 3976d7
        if project.is_fork:
Pierre-Yves Chibon 3976d7
            repopath = os.path.join(APP.config['FORK_FOLDER'], project.path)
Pierre-Yves Chibon 3976d7
Pierre-Yves Chibon 3976d7
        hook_files = os.path.join(
Pierre-Yves Chibon 3976d7
            os.path.dirname(os.path.realpath(__file__)), 'files')
Pierre-Yves Chibon 3976d7
Pierre-Yves Chibon 3976d7
        # Install the main post-receive file
Pierre-Yves Chibon 3976d7
        postreceive = os.path.join(repopath, 'hooks', 'post-receive')
Pierre-Yves Chibon 3976d7
        if not os.path.exists(postreceive):
Pierre-Yves Chibon 3976d7
            shutil.copyfile(
Pierre-Yves Chibon 3976d7
                os.path.join(hook_files, 'post-receive'),
Pierre-Yves Chibon 3976d7
                postreceive)
Pierre-Yves Chibon 3976d7
            os.chmod(postreceive, 0755)
Pierre-Yves Chibon 3976d7
Pierre-Yves Chibon 3976d7
    @classmethod
Pierre-Yves Chibon a0391b
    def install(cls, project, dbobj):
Pierre-Yves Chibon daa5de
        ''' Method called to install the hook for a project.
Pierre-Yves Chibon daa5de
Pierre-Yves Chibon daa5de
        :arg project: a ``progit.model.Project`` object to which the hook
Pierre-Yves Chibon daa5de
            should be installed
Pierre-Yves Chibon a0391b
        :arg dbobj: the DB object the hook uses to store the settings
Pierre-Yves Chibon a0391b
            information.
Pierre-Yves Chibon daa5de
Pierre-Yves Chibon daa5de
        '''
Pierre-Yves Chibon a3add0
        pass
Pierre-Yves Chibon a3add0
Pierre-Yves Chibon a3f816
    @classmethod
Pierre-Yves Chibon a3f816
    def remove(cls, project):
Pierre-Yves Chibon daa5de
        ''' Method called to remove the hook of a project.
Pierre-Yves Chibon daa5de
Pierre-Yves Chibon daa5de
        :arg project: a ``progit.model.Project`` object to which the hook
Pierre-Yves Chibon daa5de
            should be installed
Pierre-Yves Chibon daa5de
Pierre-Yves Chibon daa5de
        '''
Pierre-Yves Chibon a3add0
        pass