comparison pylons_app/lib/hooks.py @ 392:b27d32cb3157

Implemented hooks system, Added repo size hook, and active flag on ui settings in the database to able to toggle them.
author Marcin Kuzminski <marcin@python-works.com>
date Fri, 06 Aug 2010 02:03:22 +0200
parents
children 3d6d548ad3cc
comparison
equal deleted inserted replaced
391:a9814a642e11 392:b27d32cb3157
1 #!/usr/bin/env python
2 # encoding: utf-8
3 # custom hooks for application
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; version 2
9 # of the License or (at your opinion) any later version of the license.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 """
21 Created on Aug 6, 2010
22
23 @author: marcink
24 """
25
26 import sys
27 import os
28 from pylons_app.lib import helpers as h
29
30 def repo_size(ui, repo, hooktype=None, **kwargs):
31
32 if hooktype != 'changegroup':
33 return False
34
35 size_hg, size_root = 0, 0
36 for path, dirs, files in os.walk(repo.root):
37 if path.find('.hg') != -1:
38 for f in files:
39 size_hg += os.path.getsize(os.path.join(path, f))
40 else:
41 for f in files:
42 size_root += os.path.getsize(os.path.join(path, f))
43
44 size_hg_f = h.format_byte_size(size_hg)
45 size_root_f = h.format_byte_size(size_root)
46 size_total_f = h.format_byte_size(size_root + size_hg)
47 sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \
48 % (size_hg_f, size_root_f, size_total_f))