[Buildbot-commits] buildbot/buildbot trybuild.py,NONE,1.1

Brian Warner warner at users.sourceforge.net
Wed Aug 3 23:47:32 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25404/buildbot

Added Files:
	trybuild.py 
Log Message:
Revision: arch at buildbot.sf.net--2004/buildbot--dev--0--patch-264
Creator:  Brian Warner <warner at monolith.lothar.com>

start work on 'try', document the 'buildbot' command-line tool

	* buildbot/trybuild.py: new file for 'try' utilities
	(getSourceStamp): run in a tree, find out the baserev+patch
	* buildbot/test/test_vc.py (VCBase.do_getpatch): test it,
	implemented for SVN and Darcs, still working on Arch. I don't know
	how to make CVS work yet.

	* docs/buildbot.texinfo: document the 'buildbot' command-line
	tool, including the not-yet-implemented 'try' feature, and the
	in-flux .buildbot/ options directory.


--- NEW FILE: trybuild.py ---
# -*- test-case-name: buildbot.test.test_vc -*-

import os, re
from twisted.internet import utils

class SourceStampExtractor:
    def __init__(self, treetop):
        self.treetop = treetop
    def do(self, cmd):
        return utils.getProcessOutput(cmd[0], cmd[1:], env=os.environ,
                                      path=self.treetop)
    def get(self):
        d = self.getBaseRevision()
        d.addCallback(self.getPatch)
        d.addCallback(self.done)
        return d
    def readPatch(self, res, patchlevel):
        self.patch = (patchlevel, res)
    def done(self, res):
        return (self.baserev, self.patch)

class SVNExtractor(SourceStampExtractor):
    patchlevel = 0
    def getBaseRevision(self):
        d = self.do(['svn', "status", "-u"])
        d.addCallback(self.parseStatus)
        return d
    def parseStatus(self, res):
        # svn shows the base revision for each file that has been modified or
        # which needs an update. You can update each file to a different
        # version, so each file is displayed with its individual base
        # revision. It also shows the repository-wide latest revision number
        # on the last line ("Status against revision: \d+").

        # for our purposes, we use the latest revision number as the "base"
        # revision, and get a diff against that. This means we will get
        # reverse-diffs for local files that need updating, but the resulting
        # tree will still be correct. The only weirdness is that the baserev
        # that we emit may be different than the version of the tree that we
        # first checked out.

        # to do this differently would probably involve scanning the revision
        # numbers to find the max (or perhaps the min) revision, and then
        # using that as a base.

        for line in res.split("\n"):
            m = re.search(r'^Status against revision:\s+(\d+)', line)
            if m:
                num = m.group(1)
                self.baserev = int(num)
                return
        raise IndexError("Could not find 'Status against revision' in "
                         "SVN output: %s" % res)
    def getPatch(self, res):
        d = self.do(["svn", "diff", "-r%d" % self.baserev])
        d.addCallback(self.readPatch, self.patchlevel)
        return d

class BazExtractor(SourceStampExtractor):
    def getBaseRevision(self):
        d = self.do(["baz", "tree-id"])
        d.addCallback(self.parseStatus)
        return d
    def parseStatus(self, res):
        self.baserev = res.strip()
    def getPatch(self, res):
        d = self.do(["baz", "diff"])
        d.addCallback(self.readPatch, 1)
        return d

class TlaExtractor(SourceStampExtractor):
    def getBaseRevision(self):
        d = self.do(["tla", "logs", "--full", "--reverse"])
        d.addCallback(self.parseStatus)
        return d
    def parseStatus(self, res):
        lines = res.split("\n")
        self.baserev = lines[0].strip()
    def getPatch(self, res):
        d = self.do(["tla", "changes", "--diffs"])
        d.addCallback(self.readPatch, 1)
        return d

class DarcsExtractor(SourceStampExtractor):
    patchlevel = 1
    def getBaseRevision(self):
        d = self.do(["darcs", "changes", "--context"])
        d.addCallback(self.parseStatus)
        return d
    def parseStatus(self, res):
        self.baserev = res # the whole context file
    def getPatch(self, res):
        d = self.do(["darcs", "diff", "-u"])
        d.addCallback(self.readPatch, self.patchlevel)
        return d

def getSourceStamp(vctype, treetop):
    if vctype == "cvs":
        raise NotImplementedError("CVSExtractor not yet implemented")
    elif vctype == "svn":
        e = SVNExtractor(treetop)
    elif vctype == "baz":
        e = BazExtractor(treetop)
    elif vctype == "tla":
        e = TlaExtractor(treetop)
    elif vctype == "darcs":
        e = DarcsExtractor(treetop)
    else:
        raise KeyError("unknown vctype '%s'" % vctype)
    return e.get()





More information about the Commits mailing list