-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommit
executable file
·103 lines (71 loc) · 2.6 KB
/
commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python
import svn.fs, svn.repos, sys
from twisted.internet import reactor
from twisted.words.protocols.jabber import client, jid, xmlstream
from twisted.words.xish import domish
def rawDataIn(data):
print 'RECV: ' + data
def rawDataOut(data):
print 'SEND: ' + data
class Jabber:
def initFailed(self, failure):
self.xmlstream.sendFooter()
def presence(self, element):
# Open Subversion repository
repos = svn.repos.open(sys.argv[1])
fs = svn.repos.fs(repos)
author = svn.fs.revision_prop(fs, int(sys.argv[2]), svn.core.SVN_PROP_REVISION_AUTHOR).decode('utf-8')
log = svn.fs.revision_prop(fs, int(sys.argv[2]), svn.core.SVN_PROP_REVISION_LOG).decode('utf-8')
if 80 < len(log):
log = log[:77] + '...'
message = domish.Element((None, 'message'))
message['to'] = element['from']
body = message.addElement('body')
body.addContent(author)
body.addContent(' ')
body.addContent(sys.argv[2])
body.addContent(' ')
body.addContent(log)
html = message.addElement(('http://jabber.org/protocol/xhtml-im', 'html'))
body = html.addElement('body')
body.addContent(author)
body.addContent(' ')
a = body.addElement('a')
a['href'] = 'http://code.google.com/p/qubit-toolkit/source/detail?r=' + sys.argv[2]
a.addContent(sys.argv[2])
body.addContent(' ')
body.addContent(log)
self.xmlstream.send(message)
self.xmlstream.sendFooter()
def authd(self, xmlstream):
self.xmlstream = xmlstream
self.xmlstream.addObserver('/presence', self.presence)
presence = domish.Element((None, 'presence'))
self.xmlstream.send(presence)
# Timeout
reactor.callLater(5, self.xmlstream.sendFooter)
def connected(self, xmlstream):
self.xmlstream = xmlstream
self.xmlstream.rawDataInFn = rawDataIn
self.xmlstream.rawDataOutFn = rawDataOut
def end(self, xmlstream):
self.xmlstream = xmlstream
reactor.stop()
# Check arguments and print usage
if 3 != len(sys.argv):
print """
%s requires four arguments,
[1] REPOS-PATH (the path to the repository)
[2] REV (the number of the revision)
""" % sys.argv[0]
sys.exit(1)
jabber = Jabber()
jid = jid.JID('[email protected]')
password = 'example'
factory = client.XMPPClientFactory(jid, password)
factory.addBootstrap(xmlstream.INIT_FAILED_EVENT, jabber.initFailed)
factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, jabber.authd)
factory.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, jabber.connected)
factory.addBootstrap(xmlstream.STREAM_END_EVENT, jabber.end)
reactor.connectTCP('talk.google.com', 5222, factory)
reactor.run()