Package buildbot :: Package status :: Module slave
[frames] | no frames]

Source Code for Module buildbot.status.slave

  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  import time 
 17  from zope.interface import implements 
 18  from buildbot import interfaces 
 19  from buildbot.util.eventual import eventually 
 20   
21 -class SlaveStatus:
22 implements(interfaces.ISlaveStatus) 23 24 admin = None 25 host = None 26 access_uri = None 27 version = None 28 connected = False 29 graceful_shutdown = False 30
31 - def __init__(self, name):
32 self.name = name 33 self._lastMessageReceived = 0 34 self.runningBuilds = [] 35 self.graceful_callbacks = [] 36 self.connect_times = []
37
38 - def getName(self):
39 return self.name
40 - def getAdmin(self):
41 return self.admin
42 - def getHost(self):
43 return self.host
44 - def getAccessURI(self):
45 return self.access_uri
46 - def getVersion(self):
47 return self.version
48 - def isConnected(self):
49 return self.connected
50 - def lastMessageReceived(self):
51 return self._lastMessageReceived
52 - def getRunningBuilds(self):
53 return self.runningBuilds
54 - def getConnectCount(self):
55 then = time.time() - 3600 56 return len([ t for t in self.connect_times if t > then ])
57
58 - def setAdmin(self, admin):
59 self.admin = admin
60 - def setHost(self, host):
61 self.host = host
62 - def setAccessURI(self, access_uri):
64 - def setVersion(self, version):
65 self.version = version
66 - def setConnected(self, isConnected):
68 - def setLastMessageReceived(self, when):
69 self._lastMessageReceived = when
70
71 - def recordConnectTime(self):
72 # record this connnect, and keep data for the last hour 73 now = time.time() 74 self.connect_times = [ t for t in self.connect_times if t > now - 3600 ] + [ now ]
75
76 - def buildStarted(self, build):
77 self.runningBuilds.append(build)
78 - def buildFinished(self, build):
79 self.runningBuilds.remove(build)
80
81 - def getGraceful(self):
82 """Return the graceful shutdown flag""" 83 return self.graceful_shutdown
84 - def setGraceful(self, graceful):
85 """Set the graceful shutdown flag, and notify all the watchers""" 86 self.graceful_shutdown = graceful 87 for cb in self.graceful_callbacks: 88 eventually(cb, graceful)
89 - def addGracefulWatcher(self, watcher):
90 """Add watcher to the list of watchers to be notified when the 91 graceful shutdown flag is changed.""" 92 if not watcher in self.graceful_callbacks: 93 self.graceful_callbacks.append(watcher)
94 - def removeGracefulWatcher(self, watcher):
95 """Remove watcher from the list of watchers to be notified when the 96 graceful shutdown flag is changed.""" 97 if watcher in self.graceful_callbacks: 98 self.graceful_callbacks.remove(watcher)
99
100 - def asDict(self):
101 result = {} 102 # Constant 103 result['name'] = self.getName() 104 result['access_uri'] = self.getAccessURI() 105 106 # Transient (since it changes when the slave reconnects) 107 result['host'] = self.getHost() 108 result['admin'] = self.getAdmin() 109 result['version'] = self.getVersion() 110 result['connected'] = self.isConnected() 111 result['runningBuilds'] = [b.asDict() for b in self.getRunningBuilds()] 112 return result
113