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

Source Code for Module buildbot.status.buildrequest

  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  from zope.interface import implements 
 17  from twisted.python import log 
 18  from twisted.internet import defer 
 19  from buildbot import interfaces 
 20  from buildbot.util.eventual import eventually 
21 22 -class BuildRequestStatus:
23 implements(interfaces.IBuildRequestStatus) 24
25 - def __init__(self, buildername, brid, status):
26 self.buildername = buildername 27 self.brid = brid 28 self.status = status 29 self.master = status.master 30 31 self._buildrequest = None 32 self._buildrequest_lock = defer.DeferredLock()
33 34 @defer.deferredGenerator
35 - def _getBuildRequest(self):
36 """ 37 Get the underlying BuildRequest object for this status. This is a slow 38 operation! 39 40 @returns: BuildRequest instance or None, via Deferred 41 """ 42 # late binding to avoid an import cycle 43 from buildbot.process import buildrequest 44 45 # this is only set once, so no need to lock if we already have it 46 if self._buildrequest: 47 yield self._buildrequest 48 49 wfd = defer.waitForDeferred( 50 self._buildrequest_lock.acquire()) 51 yield wfd 52 wfd.getResult() 53 54 try: 55 if not self._buildrequest: 56 wfd = defer.waitForDeferred( 57 self.master.db.buildrequests.getBuildRequest(self.brid)) 58 yield wfd 59 brd = wfd.getResult() 60 61 wfd = defer.waitForDeferred( 62 buildrequest.BuildRequest.fromBrdict(self.master, brd)) 63 yield wfd 64 self._buildrequest = wfd.getResult() 65 except: # try/finally isn't allowed in generators in older Pythons 66 self._buildrequest_lock.release() 67 raise 68 69 self._buildrequest_lock.release() 70 71 yield self._buildrequest
72
73 - def buildStarted(self, build):
74 self.status._buildrequest_buildStarted(build.status) 75 self.builds.append(build.status)
76 77 # methods called by our clients 78 @defer.deferredGenerator
79 - def getBsid(self):
80 wfd = defer.waitForDeferred( 81 self._getBuildRequest()) 82 yield wfd 83 br = wfd.getResult() 84 85 yield br.bsid
86 87 @defer.deferredGenerator
88 - def getSourceStamp(self):
89 wfd = defer.waitForDeferred( 90 self._getBuildRequest()) 91 yield wfd 92 br = wfd.getResult() 93 94 yield br.source
95
96 - def getBuilderName(self):
97 return self.buildername
98 99 @defer.deferredGenerator
100 - def getBuilds(self):
101 builder = self.status.getBuilder(self.getBuilderName()) 102 builds = [] 103 104 wfd = defer.waitForDeferred( 105 self.master.db.builds.getBuildsForRequest(self.brid)) 106 yield wfd 107 bdicts = wfd.getResult() 108 109 buildnums = sorted([ bdict['number'] for bdict in bdicts ]) 110 111 for buildnum in buildnums: 112 bs = builder.getBuild(buildnum) 113 if bs: 114 builds.append(bs) 115 yield builds
116
117 - def subscribe(self, observer):
118 d = self.getBuilds() 119 def notify_old(oldbuilds): 120 for bs in oldbuilds: 121 eventually(observer, bs)
122 d.addCallback(notify_old) 123 d.addCallback(lambda _ : 124 self.status._buildrequest_subscribe(self.brid, observer)) 125 d.addErrback(log.err, 'while notifying subscribers')
126
127 - def unsubscribe(self, observer):
128 self.status._buildrequest_unsubscribe(self.brid, observer)
129 130 @defer.deferredGenerator
131 - def getSubmitTime(self):
132 wfd = defer.waitForDeferred( 133 self._getBuildRequest()) 134 yield wfd 135 br = wfd.getResult() 136 137 yield br.submittedAt
138
139 - def asDict(self):
140 result = {} 141 # Constant 142 result['source'] = None # not available sync, sorry 143 result['builderName'] = self.buildername 144 result['submittedAt'] = None # not availably sync, sorry 145 146 # Transient 147 result['builds'] = [] # not available async, sorry 148 return result
149 150 @defer.deferredGenerator
151 - def asDict_async(self):
152 result = {} 153 154 wfd = defer.waitForDeferred( 155 self.getSourceStamp()) 156 yield wfd 157 ss = wfd.getResult() 158 result['source'] = ss.asDict() 159 160 result['builderName'] = self.getBuilderName() 161 162 wfd = defer.waitForDeferred( 163 self.getSubmitTime()) 164 yield wfd 165 submittedAt = wfd.getResult() 166 result['submittedAt'] = submittedAt 167 168 wfd = defer.waitForDeferred( 169 self.getBuilds()) 170 yield wfd 171 builds = wfd.getResult() 172 173 result['builds'] = [ build.asDict() for build in builds ] 174 175 yield result
176