[Buildbot-commits] buildbot/buildbot/slave bot.py, 1.17, 1.18 commands.py, 1.52, 1.53

Brian Warner warner at users.sourceforge.net
Tue Jun 20 08:08:47 UTC 2006


Update of /cvsroot/buildbot/buildbot/buildbot/slave
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14596/buildbot/slave

Modified Files:
	bot.py commands.py 
Log Message:
[project @ slave: refactor Command startup/completion a bit]

Original author: warner at lothar.com
Date: 2006-06-20 03:55:56

Index: bot.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/slave/bot.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- bot.py	8 Feb 2006 20:50:30 -0000	1.17
+++ bot.py	20 Jun 2006 08:08:45 -0000	1.18
@@ -166,8 +166,7 @@
         log.msg(" startCommand:%s [id %s]" % (command,stepId))
         self.remoteStep = stepref
         self.remoteStep.notifyOnDisconnect(self.lostRemoteStep)
-        self.command.running = True
-        d = defer.maybeDeferred(self.command.start)
+        d = self.command.doStart()
         d.addCallback(lambda res: None)
         d.addBoth(self.commandComplete)
         return None
@@ -181,7 +180,7 @@
             # command that wasn't actually running
             log.msg(" .. but none was running")
             return
-        self.command.interrupt()
+        self.command.doInterrupt()
 
 
     def stopCommand(self):
@@ -192,8 +191,7 @@
         if not self.command:
             return
         log.msg("stopCommand: halting current command %s" % self.command)
-        self.command.running = False # shut up!
-        self.command.interrupt() # die!
+        self.command.doInterrupt() # shut up! and die!
         self.command = None # forget you!
 
     # sendUpdate is invoked by the Commands we spawn

Index: commands.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/slave/commands.py,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- commands.py	12 Jun 2006 08:36:08 -0000	1.52
+++ commands.py	20 Jun 2006 08:08:45 -0000	1.53
@@ -350,6 +350,7 @@
                     log.msg("os module is missing the 'kill' function")
                 else:
                     log.msg("trying os.kill(-pid, %d)" % (sig,))
+                    # TODO: maybe use os.killpg instead of a negative pid?
                     os.kill(-self.process.pid, sig)
                     log.msg(" signal %s sent successfully" % sig)
                     hit = 1
@@ -468,11 +469,17 @@
     def setup(self, args):
         """Override this in a subclass to extract items from the args dict."""
         pass
-        
+
+    def doStart(self):
+        self.running = True
+        d = defer.maybeDeferred(self.start)
+        d.addBoth(self.commandComplete)
+        return d
+
     def start(self):
-        """Start the command. self.running will be set just before this is
-        called. This method should return a Deferred that will fire when the
-        command has completed. The Deferred's argument will be ignored.
+        """Start the command. This method should return a Deferred that will
+        fire when the command has completed. The Deferred's argument will be
+        ignored.
 
         This method should be overridden by subclasses."""
         raise NotImplementedError, "You must implement this in a subclass"
@@ -486,12 +493,20 @@
             return
         self.builder.sendUpdate(status)
 
+    def doInterrupt(self):
+        self.running = False
+        self.interrupt()
+
     def interrupt(self):
         """Override this in a subclass to allow commands to be interrupted.
         May be called multiple times, test and set self.interrupted=True if
         this matters."""
         pass
 
+    def commandComplete(self, res):
+        self.running = False
+        return res
+
     # utility methods, mostly used by SlaveShellCommand and the like
 
     def _abandonOnFailure(self, rc):





More information about the Commits mailing list