Mercurial > kallithea
annotate rhodecode/lib/hooks.py @ 1219:ca614631c2f8
fixed tests for stable
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 05 Apr 2011 20:09:34 +0200 |
parents | a3b2b4b4e440 |
children | 9f6560667743 |
rev | line source |
---|---|
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
1 # -*- coding: utf-8 -*- |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
2 """ |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
3 rhodecode.lib.hooks |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~ |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
5 |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
6 Hooks runned by rhodecode |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
7 |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
8 :created_on: Aug 6, 2010 |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
9 :author: marcink |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
12 """ |
1217
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
13 # This program is free software: you can redistribute it and/or modify |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
14 # it under the terms of the GNU General Public License as published by |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
15 # the Free Software Foundation, either version 3 of the License, or |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
16 # (at your option) any later version. |
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
17 # |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
18 # 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
|
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
21 # GNU General Public License for more details. |
1217
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
22 # |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
23 # You should have received a copy of the GNU General Public License |
1217
a3b2b4b4e440
fixes for issue #149
Marcin Kuzminski <marcin@python-works.com>
parents:
1057
diff
changeset
|
24 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
25 import os |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
26 import sys |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
27 import getpass |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
28 |
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
|
29 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
|
30 from mercurial.node import nullrev |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
31 |
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
|
32 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
|
33 from rhodecode.lib.utils import action_logger |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
34 |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
35 def repo_size(ui, repo, hooktype=None, **kwargs): |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
36 """Presents size of repository after push |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
37 |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
38 :param ui: |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
39 :param repo: |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
40 :param hooktype: |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
41 """ |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 if hooktype != 'changegroup': |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
44 return False |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
45 size_hg, size_root = 0, 0 |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
46 for path, dirs, files in os.walk(repo.root): |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 if path.find('.hg') != -1: |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 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
|
49 try: |
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
50 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
|
51 except OSError: |
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
52 pass |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 else: |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
54 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
|
55 try: |
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
56 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
|
57 except OSError: |
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
58 pass |
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
59 |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 size_hg_f = h.format_byte_size(size_hg) |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 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
|
62 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
|
63 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
|
64 % (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
|
65 |
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
|
66 def log_pull_action(ui, repo, **kwargs): |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
67 """Logs user last pull action |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
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 :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
|
70 :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
|
71 """ |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
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 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
|
74 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
|
75 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
|
76 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
|
77 |
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
|
78 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
|
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 return 0 |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
81 |
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
|
82 def log_push_action(ui, repo, **kwargs): |
1057
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
83 """Maps user last push action to new changeset id, from mercurial |
af6ca51fb80f
rhodecode release 1.1.3 changes
Marcin Kuzminski <marcin@python-works.com>
parents:
857
diff
changeset
|
84 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
85 :param ui: |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
86 :param repo: |
503
3d6d548ad3cc
Added user action mapper to map push to changeset.
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
87 """ |
675
59670f091c76
bugfix, repo_size crashed when broken symlinks where inside a repository.
Marcin Kuzminski <marcin@python-works.com>
parents:
654
diff
changeset
|
88 |
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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 |
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
|
95 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
|
96 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
|
97 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
|
98 |
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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 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
|
104 |
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
|
105 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
|
106 |
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
|
107 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
|
108 |
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
|
109 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
|
110 |
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
|
111 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
|
112 |
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
|
113 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
|
114 |