##// END OF EJS Templates
Use webob exception as often as possible
Use webob exception as often as possible

File last commit:

r2236:37c143aa beta
r2242:87e9718a codereview
Show More
hooks.py
190 lines | 5.0 KiB | text/x-python | PythonLexer
filled in some docs for hooks
r913 # -*- coding: utf-8 -*-
"""
rhodecode.lib.hooks
~~~~~~~~~~~~~~~~~~~
Hooks runned by rhodecode
source code cleanup: remove trailing white space, normalize file endings
r1203
filled in some docs for hooks
r913 :created_on: Aug 6, 2010
:author: marcink
2012 copyrights
r1824 :copyright: (C) 2010-2012 Marcin Kuzminski <marcin@python-works.com>
filled in some docs for hooks
r913 :license: GPLv3, see COPYING for more details.
"""
fixed license issue #149
r1206 # 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.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
renamed project to rhodecode
r547 # 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.
source code cleanup: remove trailing white space, normalize file endings
r1203 #
renamed project to rhodecode
r547 # You should have received a copy of the GNU General Public License
fixed license issue #149
r1206 # along with this program. If not, see <http://www.gnu.org/licenses/>.
filled in some docs for hooks
r913 import os
import sys
renamed project to rhodecode
r547
fixed hooks for mercurial 1.9
r1415 from mercurial.scmutil import revrange
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 from mercurial.node import nullrev
added initial rc-extension module...
r2105 from rhodecode import EXTENSIONS
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 from rhodecode.lib import helpers as h
from rhodecode.lib.utils import action_logger
added initial rc-extension module...
r2105 from inspect import isfunction
renamed project to rhodecode
r547
pep8ify
r1307
made repo-size hook more generic
r2196 def _get_scm_size(alias, root_path):
if not alias.startswith('.'):
alias += '.'
size_scm, size_root = 0, 0
for path, dirs, files in os.walk(root_path):
if path.find(alias) != -1:
for f in files:
try:
size_scm += os.path.getsize(os.path.join(path, f))
except OSError:
pass
else:
for f in files:
try:
size_root += os.path.getsize(os.path.join(path, f))
except OSError:
pass
size_scm_f = h.format_byte_size(size_scm)
size_root_f = h.format_byte_size(size_root)
size_total_f = h.format_byte_size(size_root + size_scm)
return size_scm_f, size_root_f, size_total_f
renamed project to rhodecode
r547 def repo_size(ui, repo, hooktype=None, **kwargs):
#235 forking page repo group selection...
r1722 """
Presents size of repository after push
source code cleanup: remove trailing white space, normalize file endings
r1203
filled in some docs for hooks
r913 :param ui:
:param repo:
:param hooktype:
"""
renamed project to rhodecode
r547
made repo-size hook more generic
r2196 size_hg_f, size_root_f, size_total_f = _get_scm_size('.hg', repo.root)
small change for post update hook that displays repository size
r1814
last_cs = repo[len(repo) - 1]
msg = ('Repository size .hg:%s repo:%s total:%s\n'
'Last revision is now r%s:%s\n') % (
size_hg_f, size_root_f, size_total_f, last_cs.rev(), last_cs.hex()[:12]
)
sys.stdout.write(msg)
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
pep8ify
r1307
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 def log_pull_action(ui, repo, **kwargs):
#235 forking page repo group selection...
r1722 """
Logs user last pull action
source code cleanup: remove trailing white space, normalize file endings
r1203
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 :param ui:
:param repo:
"""
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added initial rc-extension module...
r2105 extras = dict(repo.ui.configitems('rhodecode_extras'))
username = extras['username']
repository = extras['repository']
added emulation of pull hook for git-backend, and dummy git-push hook
r2203 scm = extras['scm']
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 action = 'pull'
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added initial rc-extension module...
r2105 action_logger(username, action, repository, extras['ip'], commit=True)
# extension hook call
callback = getattr(EXTENSIONS, 'PULL_HOOK', None)
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added initial rc-extension module...
r2105 if isfunction(callback):
kw = {}
kw.update(extras)
callback(**kw)
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 return 0
renamed project to rhodecode
r547
pep8ify
r1307
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 def log_push_action(ui, repo, **kwargs):
#235 forking page repo group selection...
r1722 """
Maps user last push action to new changeset id, from mercurial
source code cleanup: remove trailing white space, normalize file endings
r1203
fixed @repo into :repo for docs...
r604 :param ui:
fixes issue #436 git push error
r2236 :param repo: repo object containing the `ui` object
renamed project to rhodecode
r547 """
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added initial rc-extension module...
r2105 extras = dict(repo.ui.configitems('rhodecode_extras'))
username = extras['username']
repository = extras['repository']
action = extras['action'] + ':%s'
added emulation of pull hook for git-backend, and dummy git-push hook
r2203 scm = extras['scm']
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added emulation of pull hook for git-backend, and dummy git-push hook
r2203 if scm == 'hg':
node = kwargs['node']
def get_revs(repo, rev_opt):
if rev_opt:
revs = revrange(repo, rev_opt)
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added emulation of pull hook for git-backend, and dummy git-push hook
r2203 if len(revs) == 0:
return (nullrev, nullrev)
return (max(revs), min(revs))
else:
return (len(repo) - 1, 0)
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added emulation of pull hook for git-backend, and dummy git-push hook
r2203 stop, start = get_revs(repo, [node + ':'])
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added emulation of pull hook for git-backend, and dummy git-push hook
r2203 revs = (str(repo[r]) for r in xrange(start, stop + 1))
elif scm == 'git':
revs = []
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 action = action % ','.join(revs)
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added initial rc-extension module...
r2105 action_logger(username, action, repository, extras['ip'], commit=True)
bugfix, repo_size crashed when broken symlinks where inside a repository.
r675
added initial rc-extension module...
r2105 # extension hook call
callback = getattr(EXTENSIONS, 'PUSH_HOOK', None)
if isfunction(callback):
kw = {'pushed_revs': revs}
kw.update(extras)
callback(**kw)
#48 rewrite action loggers into hooks with all changesets that are inside a push
r654 return 0
#348 added post-create repository hook
r1972
def log_create_repository(repository_dict, created_by, **kwargs):
"""
Post create repository Hook. This is a dummy function for admins to re-use
utils/conf...
r2109 if needed. It's taken from rhodecode-extensions module and executed
added initial rc-extension module...
r2105 if present
#348 added post-create repository hook
r1972
#227 Initial version of repository groups permissions system...
r1982 :param repository: dict dump of repository object
#348 added post-create repository hook
r1972 :param created_by: username who created repository
:param created_date: date of creation
available keys of repository_dict:
'repo_type',
'description',
'private',
'created_on',
'enable_downloads',
'repo_id',
'user_id',
'enable_statistics',
'clone_uri',
'fork_id',
'group_id',
'repo_name'
"""
added initial rc-extension module...
r2105 callback = getattr(EXTENSIONS, 'CREATE_REPO_HOOK', None)
if isfunction(callback):
kw = {}
kw.update(repository_dict)
kw.update({'created_by': created_by})
kw.update(kwargs)
return callback(**kw)
#348 added post-create repository hook
r1972
#227 Initial version of repository groups permissions system...
r1982 return 0