annotate rhodecode/lib/hooks.py @ 1194:07963dd1f0f1 beta

fixes for issue #133
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 02 Apr 2011 00:42:17 +0200
parents 4de3fa6290a7
children 6832ef664673
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
913
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
1 # -*- coding: utf-8 -*-
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
2 """
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
3 rhodecode.lib.hooks
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
4 ~~~~~~~~~~~~~~~~~~~
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
5
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
6 Hooks runned by rhodecode
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
7
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
8 :created_on: Aug 6, 2010
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
9 :author: marcink
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
11 :license: GPLv3, see COPYING for more details.
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
12 """
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
13 # This program is free software; you can redistribute it and/or
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
14 # modify it under the terms of the GNU General Public License
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
15 # as published by the Free Software Foundation; version 2
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
16 # of the License or (at your opinion) any later version of the license.
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
17 #
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
18 # This program is distributed in the hope that it will be useful,
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
21 # GNU General Public License for more details.
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
22 #
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
23 # You should have received a copy of the GNU General Public License
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
24 # along with this program; if not, write to the Free Software
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
26 # MA 02110-1301, USA.
913
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
27 import os
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
28 import sys
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
29 import getpass
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
30
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
31 from mercurial.cmdutil import revrange
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
32 from mercurial.node import nullrev
913
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
33
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
34 from rhodecode.lib import helpers as h
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
35 from rhodecode.lib.utils import action_logger
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
36
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
37 def repo_size(ui, repo, hooktype=None, **kwargs):
913
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
38 """Presents size of repository after push
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
39
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
40 :param ui:
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
41 :param repo:
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
42 :param hooktype:
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
43 """
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
44
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
45 if hooktype != 'changegroup':
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
46 return False
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
47 size_hg, size_root = 0, 0
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
48 for path, dirs, files in os.walk(repo.root):
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
49 if path.find('.hg') != -1:
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
50 for f in files:
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
51 try:
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
52 size_hg += os.path.getsize(os.path.join(path, f))
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
53 except OSError:
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
54 pass
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
55 else:
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
56 for f in files:
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
57 try:
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
58 size_root += os.path.getsize(os.path.join(path, f))
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
59 except OSError:
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
60 pass
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
61
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62 size_hg_f = h.format_byte_size(size_hg)
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
63 size_root_f = h.format_byte_size(size_root)
503
3d6d548ad3cc Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
64 size_total_f = h.format_byte_size(size_root + size_hg)
392
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
65 sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
66 % (size_hg_f, size_root_f, size_total_f))
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
67
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
68 def log_pull_action(ui, repo, **kwargs):
913
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
69 """Logs user last pull action
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
70
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
71 :param ui:
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
72 :param repo:
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
73 """
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
74
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
75 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
76 username = extra_params['username']
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
77 repository = extra_params['repository']
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
78 action = 'pull'
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
79
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
80 action_logger(username, action, repository, extra_params['ip'])
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
81
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
82 return 0
503
3d6d548ad3cc Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
83
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
84 def log_push_action(ui, repo, **kwargs):
913
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
85 """Maps user last push action to new changeset id, from mercurial
d173938d711b filled in some docs for hooks
Marcin Kuzminski <marcin@python-works.com>
parents: 902
diff changeset
86
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
87 :param ui:
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
88 :param repo:
503
3d6d548ad3cc Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents: 392
diff changeset
89 """
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
90
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
91 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
92 username = extra_params['username']
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
93 repository = extra_params['repository']
1114
4de3fa6290a7 #109, added manual pull of changes for repositories that have remote location filled in.
Marcin Kuzminski <marcin@python-works.com>
parents: 913
diff changeset
94 action = extra_params['action'] + ':%s'
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
95 node = kwargs['node']
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
96
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
97 def get_revs(repo, rev_opt):
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
98 if rev_opt:
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
99 revs = revrange(repo, rev_opt)
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
100
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
101 if len(revs) == 0:
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
102 return (nullrev, nullrev)
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
103 return (max(revs), min(revs))
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
104 else:
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
105 return (len(repo) - 1, 0)
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
106
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
107 stop, start = get_revs(repo, [node + ':'])
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
108
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
109 revs = (str(repo[r]) for r in xrange(start, stop + 1))
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
110
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
111 action = action % ','.join(revs)
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
112
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
113 action_logger(username, action, repository, extra_params['ip'])
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
114
654
7f5976da192c #48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
115 return 0
675
59670f091c76 bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents: 654
diff changeset
116