| OLD | NEW |
| (Empty) |
| 1 | |
| 2 from twisted.spread import pb | |
| 3 from twisted.cred import credentials | |
| 4 from twisted.internet import reactor | |
| 5 | |
| 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 | |
| 12 | |
| 13 def send(self, branch, revision, comments, files, user=None, category=None, | |
| 14 when=None, properties={}): | |
| 15 if user is None: | |
| 16 user = self.user | |
| 17 change = {'who': user, 'files': files, 'comments': comments, | |
| 18 'branch': branch, 'revision': revision, 'category': category, | |
| 19 'when': when, 'properties': properties} | |
| 20 self.num_changes += 1 | |
| 21 | |
| 22 f = pb.PBClientFactory() | |
| 23 d = f.login(credentials.UsernamePassword("change", "changepw")) | |
| 24 reactor.connectTCP(self.host, self.port, f) | |
| 25 d.addCallback(self.addChange, change) | |
| 26 return d | |
| 27 | |
| 28 def addChange(self, remote, change): | |
| 29 d = remote.callRemote('addChange', change) | |
| 30 d.addCallback(lambda res: remote.broker.transport.loseConnection()) | |
| 31 return d | |
| 32 | |
| 33 def printSuccess(self, res): | |
| 34 if self.num_changes > 1: | |
| 35 print "%d changes sent successfully" % self.num_changes | |
| 36 elif self.num_changes == 1: | |
| 37 print "change sent successfully" | |
| 38 else: | |
| 39 print "no changes to send" | |
| 40 | |
| 41 def printFailure(self, why): | |
| 42 print "change(s) NOT sent, something went wrong:" | |
| 43 print why | |
| 44 | |
| 45 def stop(self, res): | |
| 46 reactor.stop() | |
| 47 return res | |
| 48 | |
| 49 def run(self): | |
| 50 reactor.run() | |
| OLD | NEW |