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.inlineCallbacks
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 defer.returnValue(self._buildrequest) 48 return 49 50 yield self._buildrequest_lock.acquire() 51 52 try: 53 if not self._buildrequest: 54 brd = yield self.master.db.buildrequests.getBuildRequest( 55 self.brid) 56 57 br = yield buildrequest.BuildRequest.fromBrdict(self.master, 58 brd) 59 self._buildrequest = br 60 except: # try/finally isn't allowed in generators in older Pythons 61 self._buildrequest_lock.release() 62 raise 63 64 self._buildrequest_lock.release() 65 66 defer.returnValue(self._buildrequest)
67
68 - def buildStarted(self, build):
69 self.status._buildrequest_buildStarted(build.status) 70 self.builds.append(build.status)
71 72 # methods called by our clients 73 @defer.inlineCallbacks
74 - def getBsid(self):
75 br = yield self._getBuildRequest() 76 defer.returnValue(br.bsid)
77 78 @defer.inlineCallbacks
79 - def getSourceStamp(self):
80 br = yield self._getBuildRequest() 81 defer.returnValue(br.source)
82
83 - def getBuilderName(self):
84 return self.buildername
85 86 @defer.inlineCallbacks
87 - def getBuilds(self):
88 builder = self.status.getBuilder(self.getBuilderName()) 89 builds = [] 90 91 bdicts = yield self.master.db.builds.getBuildsForRequest(self.brid) 92 93 buildnums = sorted([ bdict['number'] for bdict in bdicts ]) 94 95 for buildnum in buildnums: 96 bs = builder.getBuild(buildnum) 97 if bs: 98 builds.append(bs) 99 defer.returnValue(builds)
100
101 - def subscribe(self, observer):
102 d = self.getBuilds() 103 def notify_old(oldbuilds): 104 for bs in oldbuilds: 105 eventually(observer, bs)
106 d.addCallback(notify_old) 107 d.addCallback(lambda _ : 108 self.status._buildrequest_subscribe(self.brid, observer)) 109 d.addErrback(log.err, 'while notifying subscribers')
110
111 - def unsubscribe(self, observer):
112 self.status._buildrequest_unsubscribe(self.brid, observer)
113 114 @defer.inlineCallbacks
115 - def getSubmitTime(self):
116 br = yield self._getBuildRequest() 117 defer.returnValue(br.submittedAt)
118
119 - def asDict(self):
120 result = {} 121 # Constant 122 result['source'] = None # not available sync, sorry 123 result['builderName'] = self.buildername 124 result['submittedAt'] = None # not availably sync, sorry 125 126 # Transient 127 result['builds'] = [] # not available async, sorry 128 return result
129 130 @defer.inlineCallbacks
131 - def asDict_async(self):
132 result = {} 133 134 ss = yield self.getSourceStamp() 135 result['source'] = ss.asDict() 136 result['builderName'] = self.getBuilderName() 137 result['submittedAt'] = yield self.getSubmitTime() 138 139 builds = yield self.getBuilds() 140 result['builds'] = [ build.asDict() for build in builds ] 141 142 defer.returnValue(result)
143