|
845.1.4
by Stefano Rivera
Stamp contrib |
1 |
# Copyright (c) 2008-2009, Michael Gorven
|
2 |
# Released under terms of the MIT/X/Expat Licence. See COPYING for details.
|
|
3 |
||
|
232
by Michael Gorven
bzr-hook: Update for multiple repositories. |
4 |
from urlparse import urlparse |
|
404
by Michael Gorven
bzr-hook: Fix exception handling. |
5 |
from urllib2 import urlopen |
6 |
from sys import stderr |
|
|
397
by Michael Gorven
bzr-hook: Set socket timeout to prevent commits from hanging, and catch exceptions. |
7 |
import socket |
|
133
by Michael Gorven
Add simple Bazaar hook to contact Ibid via HTTP. |
8 |
|
9 |
from bzrlib import branch |
|
|
395
by Michael Gorven
bzr-hook: Use HTTP API instead of PB. |
10 |
|
|
397
by Michael Gorven
bzr-hook: Set socket timeout to prevent commits from hanging, and catch exceptions. |
11 |
repositories = { '/srv/src/ibid/': 'ibid', |
12 |
}
|
|
|
395
by Michael Gorven
bzr-hook: Use HTTP API instead of PB. |
13 |
boturl = 'http://kennels.dyndns.org:8080' |
|
137
by Michael Gorven
Improve Bazaar hook. |
14 |
|
|
133
by Michael Gorven
Add simple Bazaar hook to contact Ibid via HTTP. |
15 |
def post_change_branch_tip(params): |
|
397
by Michael Gorven
bzr-hook: Set socket timeout to prevent commits from hanging, and catch exceptions. |
16 |
repository = urlparse(params.branch.base)[2] |
17 |
if repository.startswith('///'): |
|
18 |
repository = repository.replace('//', '', 1) |
|
19 |
if repository in repositories: |
|
|
861.1.7
by Stefano Rivera
Restore default timeouts after tweaking them |
20 |
socket.setdefaulttimeout(30) |
|
397
by Michael Gorven
bzr-hook: Set socket timeout to prevent commits from hanging, and catch exceptions. |
21 |
try: |
|
861.1.7
by Stefano Rivera
Restore default timeouts after tweaking them |
22 |
try: |
23 |
urlopen('%s/bzr/committed/%s/%s/%s' % ( |
|
24 |
boturl, |
|
25 |
repositories[repository], |
|
26 |
params.old_revno+1, |
|
27 |
params.new_revno |
|
28 |
)).close() |
|
29 |
except IOError, e: |
|
30 |
if 'reason' in e: |
|
31 |
print >> stderr, u"Couldn't notify Ibid of commit: %s" \ |
|
32 |
% (e.reason,) |
|
33 |
elif 'code' in e: |
|
34 |
print >> stderr, u"Couldn't notify Ibid of commit: HTTP " \ |
|
35 |
u"code %s" % (e.code,) |
|
36 |
else: |
|
37 |
print >> stderr, u"Couldn't notify Ibid of commit: %s" \ |
|
38 |
% (e,) |
|
39 |
finally: |
|
40 |
socket.setdefaulttimeout(None) |
|
|
133
by Michael Gorven
Add simple Bazaar hook to contact Ibid via HTTP. |
41 |
|
|
861.1.7
by Stefano Rivera
Restore default timeouts after tweaking them |
42 |
branch.Branch.hooks.install_named_hook('post_change_branch_tip', |
43 |
post_change_branch_tip, |
|
44 |
'Trigger Ibid to announce the commit') |
|
|
397
by Michael Gorven
bzr-hook: Set socket timeout to prevent commits from hanging, and catch exceptions. |
45 |
|
46 |
# vi: set et sta sw=4 ts=4:
|