[Buildbot-commits] buildbot/buildbot/changes maildirtwisted.py,1.2,1.3 maildir.py,1.5,1.6

Brian Warner warner at users.sourceforge.net
Wed Aug 10 07:06:14 UTC 2005


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

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

implement Try_Jobdir, with a unit test

	* buildbot/scheduler.py (Try_Jobdir): implement the jobdir style
	of the TryScheduler, no buildsetID or status-tracking support yet
	* buildbot/test/test_scheduler.py (Scheduling.testTryJobdir): test it

	* buildbot/changes/maildir.py (Maildir.setBasedir): make it
	possible to set the basedir after __init__ time, so it is easier
	to use as a Service-child of the BuildMaster instance

	* buildbot/changes/maildirtwisted.py (MaildirService): make a form
	that delivers messages to its Service parent instead of requiring
	a subclass to be useful. This turns out to be much easier to build
	unit tests around.

	* buildbot/scripts/tryclient.py (createJob): utility code to
	create jobfiles, will eventually be used by 'buildbot try'


Index: maildir.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/changes/maildir.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- maildir.py	6 Sep 2004 00:30:08 -0000	1.5
+++ maildir.py	10 Aug 2005 07:06:11 -0000	1.6
@@ -23,19 +23,23 @@
     started, it will run its .messageReceived method when a message is
     available.
     """
-    def __init__(self, basedir):
+    def __init__(self, basedir=None):
         """Create the Maildir watcher. BASEDIR is the maildir directory (the
         one which contains new/ and tmp/)
         """
         self.basedir = basedir
-        self.newdir = os.path.join(basedir, "new")
         self.files = []
         self.pollinterval = 10  # only used if we don't have DNotify
         self.running = 0
         self.dnotify = None
-        
+
+    def setBasedir(self, basedir):
+        self.basedir = basedir
+
     def start(self):
         """You must run start to receive any messages."""
+        assert self.basedir
+        self.newdir = os.path.join(self.basedir, "new")
         if self.running:
             return
         self.running = 1
@@ -73,6 +77,7 @@
         self.running = 0
 
     def poll(self):
+        assert self.basedir
         # see what's new
         for f in self.files:
             if not os.path.isfile(os.path.join(self.newdir, f)):

Index: maildirtwisted.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/changes/maildirtwisted.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- maildirtwisted.py	8 Dec 2003 19:06:39 -0000	1.2
+++ maildirtwisted.py	10 Aug 2005 07:06:11 -0000	1.3
@@ -13,9 +13,7 @@
 from maildir import Maildir
 
 class MaildirTwisted(Maildir, service.Service):
-    def __init__(self, maildir):
-        Maildir.__init__(self, maildir)
-        self.timeout = None
+    timeout = None
 
     def startService(self):
         self.start()
@@ -48,6 +46,20 @@
 ##         if self.callback:
 ##             self.callback(filename)
 
+class MaildirService(MaildirTwisted):
+    """I watch a maildir for new messages. I should be placed as the service
+    child of some MultiService instance. When running, I use the linux
+    dirwatcher API (if available) or poll for new files in the 'new'
+    subdirectory of my maildir path. When I discover a new message, I invoke
+    my parent's .messageReceived() method with the short filename of the new
+    message, so the full name of the new file can be obtained with
+    os.path.join(maildir, 'new', filename). I will not move or delete the
+    file on my own: the parent should do this in messageReceived().
+    """
+    def messageReceived(self, filename):
+        self.parent.messageReceived(filename)
+
+
 def test1():
     class MaildirTest(MaildirTwisted):
         def messageReceived(self, filename):





More information about the Commits mailing list