[Buildbot-commits] buildbot/buildbot master.py,1.61,1.62

Brian Warner warner at users.sourceforge.net
Sat Apr 23 10:22:13 UTC 2005


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

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

clean up ChangeSource handling

2005-04-23  Brian Warner  <warner at lothar.com>

   * buildbot/changes/changes.py: import defer, oops
   (ChangeMaster): remove the .sources list, rely upon the fact that
   MultiServices can be treated as sequences of their children. This
   cleans up the add/remove ChangeSource routines a lot, as we keep
   exactly one list of the current sources instead of three.

   * buildbot/master.py (BuildMaster.__init__): remove .sources, set
   up an empty ChangeMaster at init time.
   (BuildMaster.loadChanges): if there are changes to be had from
   disk, replace self.change_svc with the new ones. If not, keep
   using the empty ChangeMaster set up in __init__.
   (BuildMaster.loadConfig_Sources): use list(self.change_svc)
   instead of a separate list, makes the code a bit cleaner.
   * buildbot/test/test_config.py (ConfigTest.testSimple): match it
   (ConfigTest.testSources): same, also wait for loadConfig to finish.
   Extend the test to make sure we can get rid of the sources when
   we're done.


Index: master.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/master.py,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- master.py	22 Apr 2005 21:29:19 -0000	1.61
+++ master.py	23 Apr 2005 10:22:10 -0000	1.62
@@ -610,7 +610,8 @@
         self.statusTargets = []
 
         self.bots = []
-        self.sources = []
+        self.change_svc = None
+        self.useChanges(ChangeMaster())
 
         self.readConfig = False
 
@@ -646,23 +647,28 @@
             b.builder_status.addPointEvent(["master", "started"])
             b.builder_status.saveYourself()
 
-    def loadChanges(self):
-        filename = os.path.join(self.basedir, "changes.pck")
-        try:
-            self.change_svc = pickle.load(open(filename, "r"))
-        except IOError:
-            log.msg("changes.pck missing, creating new one")
-            self.change_svc = ChangeMaster()
-        except EOFError:
-            log.msg("corrupted changes.pck, creating new one")
-            self.change_svc = ChangeMaster()
-
+    def useChanges(self, changes):
+        if self.change_svc:
+            # TODO: can return a Deferred
+            self.change_svc.disownServiceParent()
+        self.change_svc = changes
         self.change_svc.basedir = self.basedir
         self.change_svc.botmaster = self.botmaster
         self.change_svc.setName("changemaster")
         self.change_svc.setServiceParent(self)
         self.dispatcher.changemaster = self.change_svc
 
+    def loadChanges(self):
+        filename = os.path.join(self.basedir, "changes.pck")
+        try:
+            changes = pickle.load(open(filename, "r"))
+        except IOError:
+            log.msg("changes.pck missing, using new one")
+            return # __init__ created a ChangeMaster() already, just use it
+        except EOFError:
+            log.msg("corrupted changes.pck, using new one")
+            return # ditto
+        self.useChanges(changes)
 
     def _handleSIGHUP(self, *args):
         reactor.callLater(0, self.loadTheConfigFile)
@@ -883,13 +889,11 @@
 
     def loadConfig_Sources(self, sources):
         # shut down any that were removed, start any that were added
-        old = self.sources
-        new = sources
+        oldsources = list(self.change_svc)
         dl = [self.change_svc.removeSource(source)
-              for source in old if source not in new]
+              for source in oldsources if source not in sources]
         [self.change_svc.addSource(source)
-         for source in new if source not in old]
-        self.sources = sources
+         for source in sources if source not in self.change_svc]
         return defer.DeferredList(dl)
 
     def loadConfig_Builders(self, newBuilders):





More information about the Commits mailing list