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