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