WebStatus: yes create public_html/ at startup, otherwise we get internal server error...
[buildbot.git] / contrib / viewcvspoll.py
blob3b2436a7a131bfab18dba56094ae2a7e0876caac
1 #! /usr/bin/python
3 """Based on the fakechanges.py contrib script"""
5 import sys
6 from twisted.spread import pb
7 from twisted.cred import credentials
8 from twisted.internet import reactor, task
9 from twisted.python import log
10 import commands, random, os.path, time, MySQLdb
12 class ViewCvsPoller:
14 def __init__(self):
15 def _load_rc():
16 import user
17 ret = {}
18 for line in open(os.path.join(user.home,".cvsblamerc")).readlines():
19 if line.find("=") != -1:
20 key, val = line.split("=")
21 ret[key.strip()] = val.strip()
22 return ret
23 # maybe add your own keys here db=xxx, user=xxx, passwd=xxx
24 self.cvsdb = MySQLdb.connect("cvs", **_load_rc())
25 #self.last_checkin = "2005-05-11" # for testing
26 self.last_checkin = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
28 def get_changes(self):
29 changes = []
31 def empty_change():
32 return {'who': None, 'files': [], 'comments': None }
33 change = empty_change()
35 cursor = self.cvsdb.cursor()
36 cursor.execute("""SELECT whoid, descid, fileid, dirid, branchid, ci_when
37 FROM checkins WHERE ci_when>='%s'""" % self.last_checkin)
38 last_checkin = None
39 for whoid, descid, fileid, dirid, branchid, ci_when in cursor.fetchall():
40 if branchid != 1: # only head
41 continue
42 cursor.execute("""SELECT who from people where id=%s""" % whoid)
43 who = cursor.fetchone()[0]
44 cursor.execute("""SELECT description from descs where id=%s""" % descid)
45 desc = cursor.fetchone()[0]
46 cursor.execute("""SELECT file from files where id=%s""" % fileid)
47 filename = cursor.fetchone()[0]
48 cursor.execute("""SELECT dir from dirs where id=%s""" % dirid)
49 dirname = cursor.fetchone()[0]
50 if who == change["who"] and desc == change["comments"]:
51 change["files"].append( "%s/%s" % (dirname, filename) )
52 elif change["who"]:
53 changes.append(change)
54 change = empty_change()
55 else:
56 change["who"] = who
57 change["files"].append( "%s/%s" % (dirname, filename) )
58 change["comments"] = desc
59 if last_checkin == None or ci_when > last_checkin:
60 last_checkin = ci_when
61 if last_checkin:
62 self.last_checkin = last_checkin
63 return changes
65 poller = ViewCvsPoller()
67 def error(*args):
68 log.err()
69 reactor.stop()
71 def poll_changes(remote):
72 print "GET CHANGES SINCE", poller.last_checkin,
73 changes = poller.get_changes()
74 for change in changes:
75 print change["who"], "\n *", "\n * ".join(change["files"])
76 remote.callRemote('addChange', change).addErrback(error)
77 print
78 reactor.callLater(60, poll_changes, remote)
80 factory = pb.PBClientFactory()
81 reactor.connectTCP("localhost", 9999, factory )
82 deferred = factory.login(credentials.UsernamePassword("change", "changepw"))
83 deferred.addCallback(poll_changes).addErrback(error)
85 reactor.run()