(closes #493) convert remaining GET form to use POST
[buildbot.git] / buildbot / clients / sendchange.py
blob4f2192bb4794e8c0d39e0bd0969d2dffbe32b147
2 from twisted.spread import pb
3 from twisted.cred import credentials
4 from twisted.internet import reactor
6 class Sender:
7 def __init__(self, master, user=None):
8 self.user = user
9 self.host, self.port = master.split(":")
10 self.port = int(self.port)
11 self.num_changes = 0
13 def send(self, branch, revision, comments, files, user=None, category=None, when=None):
14 if user is None:
15 user = self.user
16 change = {'who': user, 'files': files, 'comments': comments,
17 'branch': branch, 'revision': revision, 'category': category,
18 'when': when}
19 self.num_changes += 1
21 f = pb.PBClientFactory()
22 d = f.login(credentials.UsernamePassword("change", "changepw"))
23 reactor.connectTCP(self.host, self.port, f)
24 d.addCallback(self.addChange, change)
25 return d
27 def addChange(self, remote, change):
28 d = remote.callRemote('addChange', change)
29 d.addCallback(lambda res: remote.broker.transport.loseConnection())
30 return d
32 def printSuccess(self, res):
33 if self.num_changes > 1:
34 print "%d changes sent successfully" % self.num_changes
35 elif self.num_changes == 1:
36 print "change sent successfully"
37 else:
38 print "no changes to send"
40 def printFailure(self, why):
41 print "change(s) NOT sent, something went wrong:"
42 print why
44 def stop(self, res):
45 reactor.stop()
46 return res
48 def run(self):
49 reactor.run()