1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from twisted.spread import pb
18 from twisted.cred import credentials
19 from twisted.internet import reactor
20
22 - def __init__(self, master, auth=('change','changepw'), encoding='utf8'):
23 self.username, self.password = auth
24 self.host, self.port = master.split(":")
25 self.port = int(self.port)
26 self.encoding = encoding
27
28 - def send(self, branch, revision, comments, files, who=None, category=None,
29 when=None, properties={}, repository='', project='', revlink=''):
30 change = {'project': project, 'repository': repository, 'who': who,
31 'files': files, 'comments': comments, 'branch': branch,
32 'revision': revision, 'category': category, 'when': when,
33 'properties': properties, 'revlink': revlink}
34
35 for key in change:
36 if type(change[key]) == str:
37 change[key] = change[key].decode(self.encoding, 'replace')
38 change['files'] = list(change['files'])
39 for i, file in enumerate(change.get('files', [])):
40 if type(file) == str:
41 change['files'][i] = file.decode(self.encoding, 'replace')
42
43 f = pb.PBClientFactory()
44 d = f.login(credentials.UsernamePassword(self.username, self.password))
45 reactor.connectTCP(self.host, self.port, f)
46
47 def call_addChange(remote):
48 d = remote.callRemote('addChange', change)
49 d.addCallback(lambda res: remote.broker.transport.loseConnection())
50 return d
51 d.addCallback(call_addChange)
52
53 return d
54