[Buildbot-commits] buildbot/contrib viewcvspoll.py,NONE,1.1 README.txt,1.2,1.3
Brian Warner
warner at users.sourceforge.net
Mon Apr 17 18:31:43 UTC 2006
Update of /cvsroot/buildbot/buildbot/contrib
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16215/contrib
Modified Files:
README.txt
Added Files:
viewcvspoll.py
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-498
Creator: Brian Warner <warner at lothar.com>
added contrib/viewcvspoll.py
* contrib/viewcvspoll.py: script to poll a viewcvs database for
changes, then deliver them over PB to a remote buildmaster.
Index: README.txt
===================================================================
RCS file: /cvsroot/buildbot/buildbot/contrib/README.txt,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- README.txt 17 Apr 2006 18:11:42 -0000 1.2
+++ README.txt 17 Apr 2006 18:31:41 -0000 1.3
@@ -29,3 +29,9 @@
internally rather than expecting to run from a cronjob),
polls an SVN repository every 10 minutes. It expects the
svnurl and buildmaster location as command-line arguments.
+
+viewcvspoll.py: a standalone script which loops every 60 seconds and polls a
+ (local?) MySQL database (presumably maintained by ViewCVS?)
+ for information about new CVS changes, then delivers them
+ over PB to a remote buildmaster's PBChangeSource. Contributed
+ by Stephen Kennedy.
--- NEW FILE: viewcvspoll.py ---
#! /usr/bin/python
"""Based on the fakechanges.py contrib script"""
import sys
from twisted.spread import pb
from twisted.cred import credentials
from twisted.internet import reactor, task
from twisted.python import log
import commands, random, os.path, time, MySQLdb
class ViewCvsPoller:
def __init__(self):
def _load_rc():
import user
ret = {}
for line in open(os.path.join(user.home,".cvsblamerc")).readlines():
if line.find("=") != -1:
key, val = line.split("=")
ret[key.strip()] = val.strip()
return ret
# maybe add your own keys here db=xxx, user=xxx, passwd=xxx
self.cvsdb = MySQLdb.connect("cvs", **_load_rc())
#self.last_checkin = "2005-05-11" # for testing
self.last_checkin = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
def get_changes(self):
changes = []
def empty_change():
return {'who': None, 'files': [], 'comments': None }
change = empty_change()
cursor = self.cvsdb.cursor()
cursor.execute("""SELECT whoid, descid, fileid, dirid, branchid, ci_when
FROM checkins WHERE ci_when>='%s'""" % self.last_checkin)
last_checkin = None
for whoid, descid, fileid, dirid, branchid, ci_when in cursor.fetchall():
if branchid != 1: # only head
continue
cursor.execute("""SELECT who from people where id=%s""" % whoid)
who = cursor.fetchone()[0]
cursor.execute("""SELECT description from descs where id=%s""" % descid)
desc = cursor.fetchone()[0]
cursor.execute("""SELECT file from files where id=%s""" % fileid)
filename = cursor.fetchone()[0]
cursor.execute("""SELECT dir from dirs where id=%s""" % dirid)
dirname = cursor.fetchone()[0]
if who == change["who"] and desc == change["comments"]:
change["files"].append( "%s/%s" % (dirname, filename) )
elif change["who"]:
changes.append(change)
change = empty_change()
else:
change["who"] = who
change["files"].append( "%s/%s" % (dirname, filename) )
change["comments"] = desc
if last_checkin == None or ci_when > last_checkin:
last_checkin = ci_when
if last_checkin:
self.last_checkin = last_checkin
return changes
poller = ViewCvsPoller()
def error(*args):
log.err()
reactor.stop()
def poll_changes(remote):
print "GET CHANGES SINCE", poller.last_checkin,
changes = poller.get_changes()
for change in changes:
print change["who"], "\n *", "\n * ".join(change["files"])
remote.callRemote('addChange', change).addErrback(error)
print
reactor.callLater(60, poll_changes, remote)
factory = pb.PBClientFactory()
reactor.connectTCP("localhost", 9999, factory )
deferred = factory.login(credentials.UsernamePassword("change", "changepw"))
deferred.addCallback(poll_changes).addErrback(error)
reactor.run()
More information about the Commits
mailing list