[Buildbot-devel] Simple FilePoller change source help

Alexander Sack pisymbol at gmail.com
Fri Jul 6 17:13:36 UTC 2012


Hello:

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
  3
  4 from buildbot.changes import base
  5 from twisted.internet import defer
  6 from twisted.python import log
  7
  8 class FilePoller(base.PollingChangeSource):
  9     """ Simple poller that watches a file for changes """
 10
 11     def __init__(self, fileName = '', pollInterval = 30):
 12         self.fileName = os.path.realpath(fileName)
 13         self.hash = self._hash()
 14         self.pollInterval = pollInterval
 15
 16     def poll(self):
 17         d = defer.Deferred()
 18         d.addCallback(self._poll)
 19         return d
 20
 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
= 'master'))
 26             yield w
 27             log.msg(w.getResult())
 28
 29     def _hash(self):
 30         try:
 31             file = open(self.fileName, 'r')
 32             fileContents = file.readlines()
 33             file.close()
 34             return hashlib.sha1(str(fileContents)).hexdigest()
 35         except:
 36             log.err('could not calculate sha1 hash of %s' % self.filename)
 37             return ''
 38
 39     def startService(self):
 40             base.PollingChangeSource.startService(self)

In my master.cfg, I have added a SingleBranchScheduler() as per the sample file:

 47 c['schedulers'].append(SingleBranchScheduler(
 48                             name="all",
 49
change_filter=filter.ChangeFilter(branch='master'),
 50                             treeStableTimer=None,
 51                             builderNames=["dell-builder"]))

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).

-aps




More information about the devel mailing list