freshcvs.py :  » Build » Buildbot » buildbot-0.8.0 » buildbot » changes » 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 » buildbot » changes » freshcvs.py

import os.path

from zope.interface import implements
from twisted.cred import credentials
from twisted.spread import pb
from twisted.application.internet import TCPClient
from twisted.python import log

import cvstoys.common # to make sure VersionedPatch gets registered

from buildbot.interfaces import IChangeSource
from buildbot.pbutil import ReconnectingPBClientFactory
from buildbot.changes.changes import Change
from buildbot import util

class FreshCVSListener(pb.Referenceable):
    def remote_notify(self, root, files, message, user):
        try:
            self.source.notify(root, files, message, user)
        except Exception:
            print "notify failed"
            log.err()

    def remote_goodbye(self, message):
        pass

class FreshCVSConnectionFactory(ReconnectingPBClientFactory):

    def gotPerspective(self, perspective):
        log.msg("connected to FreshCVS daemon")
        ReconnectingPBClientFactory.gotPerspective(self, perspective)
        self.source.connected = True
        # TODO: freshcvs-1.0.10 doesn't handle setFilter correctly, it will
        # be fixed in the upcoming 1.0.11 . I haven't been able to test it
        # to make sure the failure mode is survivable, so I'll just leave
        # this out for now.
        return
        if self.source.prefix is not None:
            pathfilter = "^%s" % self.source.prefix
            d = perspective.callRemote("setFilter",
                                       None, pathfilter, None)
            # ignore failures, setFilter didn't work in 1.0.10 and this is
            # just an optimization anyway
            d.addErrback(lambda f: None)

    def clientConnectionLost(self, connector, reason):
        ReconnectingPBClientFactory.clientConnectionLost(self, connector,
                                                         reason)
        self.source.connected = False

class FreshCVSSourceNewcred(TCPClient, util.ComparableMixin):
    """This source will connect to a FreshCVS server associated with one or
    more CVS repositories. Each time a change is committed to a repository,
    the server will send us a message describing the change. This message is
    used to build a Change object, which is then submitted to the
    ChangeMaster.

    This class handles freshcvs daemons which use newcred. CVSToys-1.0.9
    does not, later versions might.
    """

    implements(IChangeSource)
    compare_attrs = ["host", "port", "username", "password", "prefix"]

    changemaster = None # filled in when we're added
    connected = False

    def __init__(self, host, port, user, passwd, prefix=None):
        self.host = host
        self.port = port
        self.username = user
        self.password = passwd
        if prefix is not None and not prefix.endswith("/"):
            log.msg("WARNING: prefix '%s' should probably end with a slash" \
                    % prefix)
        self.prefix = prefix
        self.listener = l = FreshCVSListener()
        l.source = self
        self.factory = f = FreshCVSConnectionFactory()
        f.source = self
        self.creds = credentials.UsernamePassword(user, passwd)
        f.startLogin(self.creds, client=l)
        TCPClient.__init__(self, host, port, f)

    def __repr__(self):
        return "<FreshCVSSource where=%s, prefix=%s>" % \
               ((self.host, self.port), self.prefix)

    def describe(self):
        online = ""
        if not self.connected:
            online = " [OFFLINE]"
        return "freshcvs %s:%s%s" % (self.host, self.port, online)

    def notify(self, root, files, message, user):
        pathnames = []
        isdir = 0
        for f in files:
            if not isinstance(f, (cvstoys.common.VersionedPatch,
                                  cvstoys.common.Directory)):
                continue
            pathname, filename = f.pathname, f.filename
            #r1, r2 = getattr(f, 'r1', None), getattr(f, 'r2', None)
            if isinstance(f, cvstoys.common.Directory):
                isdir = 1
            path = os.path.join(pathname, filename)
            log.msg("FreshCVS notify '%s'" % path)
            if self.prefix:
                if path.startswith(self.prefix):
                    path = path[len(self.prefix):]
                else:
                    continue
            pathnames.append(path)
        if pathnames:
            # now() is close enough: FreshCVS *is* realtime, after all
            when=util.now()
            c = Change(user, pathnames, message, isdir, when=when)
            self.parent.addChange(c)

class FreshCVSSourceOldcred(FreshCVSSourceNewcred):
    """This is for older freshcvs daemons (from CVSToys-1.0.9 and earlier).
    """

    def __init__(self, host, port, user, passwd,
                 serviceName="cvstoys.notify", prefix=None):
        self.host = host
        self.port = port
        self.prefix = prefix
        self.listener = l = FreshCVSListener()
        l.source = self
        self.factory = f = FreshCVSConnectionFactory()
        f.source = self
        f.startGettingPerspective(user, passwd, serviceName, client=l)
        TCPClient.__init__(self, host, port, f)

    def __repr__(self):
        return "<FreshCVSSourceOldcred where=%s, prefix=%s>" % \
               ((self.host, self.port), self.prefix)

# this is suitable for CVSToys-1.0.10 and later. If you run CVSToys-1.0.9 or
# earlier, use FreshCVSSourceOldcred instead.
FreshCVSSource = FreshCVSSourceNewcred

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.