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