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

Source Code for Module buildbot.clients.base

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