viewcvspoll.py :  » Build » Buildbot » buildbot-0.8.0 » contrib » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Build » Buildbot 
Buildbot » buildbot 0.8.0 » contrib » viewcvspoll.py
#! /usr/bin/python

"""Based on the fakechanges.py contrib script"""

import os.path
import time
import MySQLdb #@UnresolvedImport

from twisted.spread import pb
from twisted.cred import credentials
from twisted.internet import reactor
from twisted.python import log


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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.