Mercurial > kallithea
comparison pylons_app/lib/hooks.py @ 503:3d6d548ad3cc
Added user action mapper to map push to changeset.
made exception in simplehg python 2.5 ready
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 24 Sep 2010 18:13:29 +0200 |
parents | b27d32cb3157 |
children | 39203995f2c4 |
comparison
equal
deleted
inserted
replaced
502:ac32a026c306 | 503:3d6d548ad3cc |
---|---|
24 """ | 24 """ |
25 | 25 |
26 import sys | 26 import sys |
27 import os | 27 import os |
28 from pylons_app.lib import helpers as h | 28 from pylons_app.lib import helpers as h |
29 from pylons_app.model import meta | |
30 from pylons_app.model.db import UserLog, User | |
29 | 31 |
30 def repo_size(ui, repo, hooktype=None, **kwargs): | 32 def repo_size(ui, repo, hooktype=None, **kwargs): |
31 | 33 |
32 if hooktype != 'changegroup': | 34 if hooktype != 'changegroup': |
33 return False | 35 return False |
34 | |
35 size_hg, size_root = 0, 0 | 36 size_hg, size_root = 0, 0 |
36 for path, dirs, files in os.walk(repo.root): | 37 for path, dirs, files in os.walk(repo.root): |
37 if path.find('.hg') != -1: | 38 if path.find('.hg') != -1: |
38 for f in files: | 39 for f in files: |
39 size_hg += os.path.getsize(os.path.join(path, f)) | 40 size_hg += os.path.getsize(os.path.join(path, f)) |
41 for f in files: | 42 for f in files: |
42 size_root += os.path.getsize(os.path.join(path, f)) | 43 size_root += os.path.getsize(os.path.join(path, f)) |
43 | 44 |
44 size_hg_f = h.format_byte_size(size_hg) | 45 size_hg_f = h.format_byte_size(size_hg) |
45 size_root_f = h.format_byte_size(size_root) | 46 size_root_f = h.format_byte_size(size_root) |
46 size_total_f = h.format_byte_size(size_root + size_hg) | 47 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 sys.stdout.write('Repository size .hg:%s repo:%s total:%s\n' \ |
48 % (size_hg_f, size_root_f, size_total_f)) | 49 % (size_hg_f, size_root_f, size_total_f)) |
50 | |
51 user_action_mapper(ui, repo, hooktype, **kwargs) | |
52 | |
53 def user_action_mapper(ui, repo, hooktype=None, **kwargs): | |
54 """ | |
55 Maps user last push action to new changeset id, from mercurial | |
56 @param ui: | |
57 @param repo: | |
58 @param hooktype: | |
59 """ | |
60 | |
61 try: | |
62 sa = meta.Session | |
63 username = kwargs['url'].split(':')[-1] | |
64 user_log = sa.query(UserLog)\ | |
65 .filter(UserLog.user == sa.query(User)\ | |
66 .filter(User.username == username).one())\ | |
67 .order_by(UserLog.user_log_id.desc()).first() | |
68 | |
69 if not user_log.revision: | |
70 user_log.revision = str(repo['tip']) | |
71 sa.add(user_log) | |
72 sa.commit() | |
73 | |
74 except Exception, e: | |
75 sa.rollback() | |
76 raise | |
77 finally: | |
78 meta.Session.remove() |