Package buildbot :: Package clients :: Module base
[frames] | no frames]

Source Code for Module buildbot.clients.base

  1   
  2  import re 
  3   
  4  from twisted.spread import pb 
  5  from twisted.cred import credentials, error 
  6  from twisted.internet import reactor 
  7   
8 -class StatusClient(pb.Referenceable):
9 """To use this, call my .connected method with a RemoteReference to the 10 buildmaster's StatusClientPerspective object. 11 """ 12
13 - def __init__(self, events):
14 self.builders = {} 15 self.events = events
16
17 - def connected(self, remote):
18 print "connected" 19 self.remote = remote 20 remote.callRemote("subscribe", self.events, 5, self)
21
22 - def remote_builderAdded(self, buildername, builder):
23 print "builderAdded", buildername
24
25 - def remote_builderRemoved(self, buildername):
26 print "builderRemoved", buildername
27
28 - def remote_builderChangedState(self, buildername, state, eta):
29 print "builderChangedState", buildername, state, eta
30
31 - def remote_buildStarted(self, buildername, build):
32 print "buildStarted", buildername
33
34 - def remote_buildFinished(self, buildername, build, results):
35 print "buildFinished", results
36
37 - def remote_buildETAUpdate(self, buildername, build, eta):
38 print "ETA", buildername, eta
39
40 - def remote_stepStarted(self, buildername, build, stepname, step):
41 print "stepStarted", buildername, stepname
42
43 - def remote_stepFinished(self, buildername, build, stepname, step, results):
44 print "stepFinished", buildername, stepname, results
45
46 - def remote_stepETAUpdate(self, buildername, build, stepname, step, 47 eta, expectations):
48 print "stepETA", buildername, stepname, eta
49
50 - def remote_logStarted(self, buildername, build, stepname, step, 51 logname, log):
52 print "logStarted", buildername, stepname
53
54 - def remote_logFinished(self, buildername, build, stepname, step, 55 logname, log):
56 print "logFinished", buildername, stepname
57
58 - def remote_logChunk(self, buildername, build, stepname, step, logname, log, 59 channel, text):
60 ChunkTypes = ["STDOUT", "STDERR", "HEADER"] 61 print "logChunk[%s]: %s" % (ChunkTypes[channel], text)
62
63 -class TextClient:
64 - def __init__(self, master, events="steps", username="statusClient", passwd="clientpw"):
65 """ 66 @type master: string 67 @param master: a host:port string to masters L{buildbot.status.client.PBListener} 68 69 @type username: string 70 @param username: 71 72 @type passwd: string 73 @param passwd: 74 75 @type events: string, one of builders, builds, steps, logs, full 76 @param events: specify what level of detail should be reported. 77 - 'builders': only announce new/removed Builders 78 - 'builds': also announce builderChangedState, buildStarted, and 79 buildFinished 80 - 'steps': also announce buildETAUpdate, stepStarted, stepFinished 81 - 'logs': also announce stepETAUpdate, logStarted, logFinished 82 - 'full': also announce log contents 83 """ 84 self.master = master 85 self.username = username 86 self.passwd = passwd 87 self.listener = StatusClient(events)
88
89 - def run(self):
90 """Start the TextClient.""" 91 self.startConnecting() 92 reactor.run()
93
94 - def startConnecting(self):
95 try: 96 host, port = re.search(r'(.+):(\d+)', self.master).groups() 97 port = int(port) 98 except: 99 print "unparseable master location '%s'" % self.master 100 print " expecting something more like localhost:8007" 101 raise 102 cf = pb.PBClientFactory() 103 creds = credentials.UsernamePassword(self.username, self.passwd) 104 d = cf.login(creds) 105 reactor.connectTCP(host, port, cf) 106 d.addCallbacks(self.connected, self.not_connected) 107 return d
108 - def connected(self, ref):
109 ref.notifyOnDisconnect(self.disconnected) 110 self.listener.connected(ref)
111 - def not_connected(self, why):
112 if why.check(error.UnauthorizedLogin): 113 print """ 114 Unable to login.. are you sure we are connecting to a 115 buildbot.status.client.PBListener port and not to the slaveport? 116 """ 117 reactor.stop() 118 return why
119 - def disconnected(self, ref):
120 print "lost connection" 121 # we can get here in one of two ways: the buildmaster has 122 # disconnected us (probably because it shut itself down), or because 123 # we've been SIGINT'ed. In the latter case, our reactor is already 124 # shut down, but we have no easy way of detecting that. So protect 125 # our attempt to shut down the reactor. 126 try: 127 reactor.stop() 128 except RuntimeError: 129 pass
130