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