[Buildbot-commits] buildbot/buildbot/process base.py,1.57,1.58 builder.py,1.28,1.29

Brian Warner warner at users.sourceforge.net
Wed Aug 17 02:15:40 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot/process
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31918/buildbot/process

Modified Files:
	base.py builder.py 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-295
Creator:  Brian Warner <warner at monolith.lothar.com>

implement IBuildSetStatus/IBuildRequestStatus, wire them into place

	* buildbot/status/builder.py: implement IBuildSetStatus and
	IBuildRequestStatus, wire them into place.
	* buildbot/buildset.py: same. Add ID, move wait-until-finished
	methods into the BuildSetStatus object.
	* buildbot/interfaces.py: same
	(IStatus.getBuildSets): new method to get pending BuildSets
	(IStatusReceiver.buildsetSubmitted): new method which hears about
	new BuildSets
	* buildbot/master.py (BuildMaster.submitBuildSet): same
	* buildbot/process/base.py (BuildRequest): same, replace
	waitUntilStarted with subscribe/unsubscribe
	* buildbot/process/builder.py (BuilderControl.forceBuild): use
	subscribe instead of waitUntilStarted
	* buildbot/status/base.py (StatusReceiver.buildsetSubmitted): stub
	for new method
	* buildbot/status/client.py (StatusClientPerspective.builderRemoved): 
	same
	* buildbot/test/test_buildreq.py: update for new code
	* buildbot/test/test_control.py (Force.testRequest): same


Index: base.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/process/base.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- base.py	19 Jul 2005 23:23:21 -0000	1.57
+++ base.py	17 Aug 2005 02:15:37 -0000	1.58
@@ -12,7 +12,7 @@
 from buildbot.twcompat import implements
 from buildbot.util import now
 from buildbot.status.builder import SUCCESS, WARNINGS, FAILURE, EXCEPTION
-from buildbot.status.builder import Results
+from buildbot.status.builder import Results, BuildRequestStatus
 from buildbot.status.progress import BuildProgress
 
 class BuildRequest:
@@ -31,6 +31,9 @@
     I may be part of a BuildSet, in which case I will report status results
     to it.
 
+    I am paired with a BuildRequestStatus object, to which I feed status
+    information.
+
     @type source: a L{buildbot.buildset.SourceStamp} instance.   
     @ivar source: the source code that this BuildRequest use
 
@@ -55,12 +58,15 @@
     else:
         __implements__ = interfaces.IBuildRequestControl,
 
-    def __init__(self, reason, source):
+    def __init__(self, reason, source, builderName=None):
+        # TODO: remove the =None on builderName, it is there so I don't have
+        # to change a lot of tests that create BuildRequest objects
         assert interfaces.ISourceStamp(source, None)
         self.reason = reason
         self.source = source
         self.start_watchers = []
         self.finish_watchers = []
+        self.status = BuildRequestStatus(source, builderName)
 
     def canBeMergedWith(self, other):
         return self.source.canBeMergedWith(other.source)
@@ -76,17 +82,6 @@
                 reasons.append(req.reason)
         return ", ".join(reasons)
 
-    def waitUntilStarted(self):
-        """Get a Deferred that will fire (with a
-        L{buildbot.interfaces.IBuildControl} instance) when the build starts.
-        TODO: there could be multiple Builds to satisfy a BuildRequest, but
-        this API only allows you to wait for the first one."""
-        # TODO: if you call this after the build has started, the Deferred
-        # will never fire.
-        d = defer.Deferred()
-        self.start_watchers.append(d)
-        return d
-
     def waitUntilFinished(self):
         """Get a Deferred that will fire (with a
         L{buildbot.interfaces.IBuildStatus} instance when the build
@@ -107,9 +102,11 @@
         times, since interrupted builds and lost buildslaves may force
         multiple Builds to be run until the fate of the BuildRequest is known
         for certain."""
-        for w in self.start_watchers:
-            w.callback(build)
-        self.start_watchers = []
+        for o in self.start_watchers[:]:
+            # these observers get the IBuildControl
+            o(build)
+        # while these get the IBuildStatus
+        self.status.buildStarted(buildstatus)
 
     def finished(self, buildstatus):
         """This is called by the Builder when the BuildRequest has been
@@ -122,6 +119,12 @@
         self.finish_watchers = []
 
     # IBuildRequestControl
+
+    def subscribe(self, observer):
+        self.start_watchers.append(observer)
+    def unsubscribe(self, observer):
+        self.start_watchers.remove(observer)
+
     def cancel(self):
         """Cancel this request. This can only be successful if the Build has
         not yet been started.

Index: builder.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/process/builder.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- builder.py	20 Jul 2005 05:36:56 -0000	1.28
+++ builder.py	17 Aug 2005 02:15:37 -0000	1.29
@@ -521,9 +521,13 @@
         __implements__ = interfaces.IBuilderControl,
 
     def forceBuild(self, who, reason):
-        """This is a shortcut for building the current HEAD. You get back a
-        BuildRequest, just as if you'd asked politely. To get control of the
-        resulting build, you'll need to wait for req.waitUntilStarted().
+        """This is a shortcut for building the current HEAD.
+
+        (false: You get back a BuildRequest, just as if you'd asked politely.
+        To get control of the resulting build, you'll need use
+        req.subscribe() .)
+
+        (true: You get back a Deferred that fires with an IBuildControl)
 
         This shortcut peeks into the Builder and raises an exception if there
         is no slave available, to make backwards-compatibility a little
@@ -540,7 +544,22 @@
             raise interfaces.NoSlaveError("There are no slaves connected")
         req = base.BuildRequest(reason, sourcestamp.SourceStamp())
         self.requestBuild(req)
-        return req.waitUntilStarted()
+        # this is a hack that fires the Deferred for the first build and
+        # ignores any others
+        class Watcher:
+            def __init__(self, req):
+                self.req = req
+            def wait(self):
+                self.d = d = defer.Deferred()
+                req.subscribe(self.started)
+                return d
+            def started(self, bs):
+                if self.d:
+                    self.req.unsubscribe(self.started)
+                    self.d.callback(bs)
+                    self.d = None
+        w = Watcher(req)
+        return w.wait()
 
     def requestBuild(self, req):
         self.original.submitBuildRequest(req)





More information about the Commits mailing list