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='', vc=None, project='',
30 revlink=''):
31 change = {'project': project, 'repository': repository, 'who': who,
32 'files': files, 'comments': comments, 'branch': branch,
33 'revision': revision, 'category': category, 'when': when,
34 'properties': properties, 'revlink': revlink, 'src': vc}
35
36 for key in change:
37 if type(change[key]) == str:
38 change[key] = change[key].decode(self.encoding, 'replace')
39 change['files'] = list(change['files'])
40 for i, file in enumerate(change.get('files', [])):
41 if type(file) == str:
42 change['files'][i] = file.decode(self.encoding, 'replace')
43
44 f = pb.PBClientFactory()
45 d = f.login(credentials.UsernamePassword(self.username, self.password))
46 reactor.connectTCP(self.host, self.port, f)
47
48 def call_addChange(remote):
49 d = remote.callRemote('addChange', change)
50 d.addCallback(lambda res: remote.broker.transport.loseConnection())
51 return d
52 d.addCallback(call_addChange)
53
54 return d
55