[Buildbot-devel] Simple FilePoller change source help
pisymbol at gmail.com
Fri Jul 6 17:13:36 UTC 2012
I'm new to Buildbot development and need a little guidance.
What I want to do is poll the contents of a particular file, and when
it changes, submit a Change().
I realize this is slightly out of the standard VCS model, but I
thought something like this would work (this is alpha code):
1 import hashlib
2 import os
4 from buildbot.changes import base
5 from twisted.internet import defer
6 from twisted.python import log
8 class FilePoller(base.PollingChangeSource):
9 """ Simple poller that watches a file for changes """
11 def __init__(self, fileName = '', pollInterval = 30):
12 self.fileName = os.path.realpath(fileName)
13 self.hash = self._hash()
14 self.pollInterval = pollInterval
16 def poll(self):
17 d = defer.Deferred()
19 return d
21 def _poll(self):
22 hash = _hash(self)
23 if hash != self.hash:
24 self.hash = hash
25 w = defer.waitForDeferred(self.master.addChange(branch
26 yield w
29 def _hash(self):
31 file = open(self.fileName, 'r')
32 fileContents = file.readlines()
34 return hashlib.sha1(str(fileContents)).hexdigest()
36 log.err('could not calculate sha1 hash of %s' % self.filename)
37 return ''
39 def startService(self):
In my master.cfg, I have added a SingleBranchScheduler() as per the sample file:
I do see the poll() method getting initially called and then that's it.
I based most of this code on reading the Customization section in the
manual and the GitPoller() source. I haven't delved yet into Buildbot
core just yet! :-)
I realize I should probably use a PBChangeSource() and an external
script but I am trying to understand Buildbot's hook architecture
since I really like it.
What am I doing wrong? I am using 0.86p1 on CentOS 5.4 (python 2.6).
More information about the devel