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