3 """Based on the fakechanges.py contrib script"""
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
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()
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
):
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
)
39 for whoid
, descid
, fileid
, dirid
, branchid
, ci_when
in cursor
.fetchall():
40 if branchid
!= 1: # only head
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
) )
53 changes
.append(change
)
54 change
= empty_change()
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
62 self
.last_checkin
= last_checkin
65 poller
= ViewCvsPoller()
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
)
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
)