##// END OF EJS Templates
filled in some docs for hooks
marcink -
r913:d173938d beta
parent child Browse files
Show More
@@ -1,105 +1,116 b''
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # custom hooks for application
4 # Copyright (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
5 #
1 # -*- coding: utf-8 -*-
2 """
3 rhodecode.lib.hooks
4 ~~~~~~~~~~~~~~~~~~~
5
6 Hooks runned by rhodecode
7
8 :created_on: Aug 6, 2010
9 :author: marcink
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com>
11 :license: GPLv3, see COPYING for more details.
12 """
6 13 # This program is free software; you can redistribute it and/or
7 14 # modify it under the terms of the GNU General Public License
8 15 # as published by the Free Software Foundation; version 2
9 16 # of the License or (at your opinion) any later version of the license.
10 17 #
11 18 # This program is distributed in the hope that it will be useful,
12 19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 21 # GNU General Public License for more details.
15 22 #
16 23 # You should have received a copy of the GNU General Public License
17 24 # along with this program; if not, write to the Free Software
18 25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 26 # MA 02110-1301, USA.
20 """
21 Created on Aug 6, 2010
27 import os
28 import sys
29 import getpass
22 30
23 @author: marcink
24 """
25 31 from mercurial.cmdutil import revrange
26 32 from mercurial.node import nullrev
33
27 34 from rhodecode.lib import helpers as h
28 35 from rhodecode.lib.utils import action_logger
29 import os
30 import sys
31 36
32 37 def repo_size(ui, repo, hooktype=None, **kwargs):
38 """Presents size of repository after push
39
40 :param ui:
41 :param repo:
42 :param hooktype:
43 """
33 44
34 45 if hooktype != 'changegroup':
35 46 return False
36 47 size_hg, size_root = 0, 0
37 48 for path, dirs, files in os.walk(repo.root):
38 49 if path.find('.hg') != -1:
39 50 for f in files:
40 51 try:
41 52 size_hg += os.path.getsize(os.path.join(path, f))
42 53 except OSError:
43 54 pass
44 55 else:
45 56 for f in files:
46 57 try:
47 58 size_root += os.path.getsize(os.path.join(path, f))
48 59 except OSError:
49 60 pass
50 61
51 62 size_hg_f = h.format_byte_size(size_hg)
52 63 size_root_f = h.format_byte_size(size_root)
53 64 size_total_f = h.format_byte_size(size_root + size_hg)
54 65 sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \
55 66 % (size_hg_f, size_root_f, size_total_f))
56 67
57 68 def log_pull_action(ui, repo, **kwargs):
58 """
59 Logs user last pull action
69 """Logs user last pull action
70
60 71 :param ui:
61 72 :param repo:
62 73 """
63 74
64 75 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
65 76 username = extra_params['username']
66 77 repository = extra_params['repository']
67 78 action = 'pull'
68 79
69 80 action_logger(username, action, repository, extra_params['ip'])
70 81
71 82 return 0
72 83
73 84 def log_push_action(ui, repo, **kwargs):
74 """
75 Maps user last push action to new changeset id, from mercurial
85 """Maps user last push action to new changeset id, from mercurial
86
76 87 :param ui:
77 88 :param repo:
78 89 """
79 90
80 91 extra_params = dict(repo.ui.configitems('rhodecode_extras'))
81 92 username = extra_params['username']
82 93 repository = extra_params['repository']
83 94 action = 'push:%s'
84 95 node = kwargs['node']
85 96
86 97 def get_revs(repo, rev_opt):
87 98 if rev_opt:
88 99 revs = revrange(repo, rev_opt)
89 100
90 101 if len(revs) == 0:
91 102 return (nullrev, nullrev)
92 103 return (max(revs), min(revs))
93 104 else:
94 105 return (len(repo) - 1, 0)
95 106
96 107 stop, start = get_revs(repo, [node + ':'])
97 108
98 109 revs = (str(repo[r]) for r in xrange(start, stop + 1))
99 110
100 111 action = action % ','.join(revs)
101 112
102 113 action_logger(username, action, repository, extra_params['ip'])
103 114
104 115 return 0
105 116
General Comments 0
You need to be logged in to leave comments. Login now