[Buildbot-commits] buildbot/buildbot/slave commands.py,1.75,1.76

Brian Warner warner at users.sourceforge.net
Tue Jan 23 05:50:00 UTC 2007


Update of /cvsroot/buildbot/buildbot/buildbot/slave
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv1130/buildbot/slave

Modified Files:
	commands.py 
Log Message:
[project @ add support for bzr (bazaar-ng)]

Original author: warner at lothar.com
Date: 2007-01-11 00:57:02

Index: commands.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/slave/commands.py,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- commands.py	11 Dec 2006 09:11:26 -0000	1.75
+++ commands.py	23 Jan 2007 05:49:58 -0000	1.76
@@ -1932,6 +1932,128 @@
 registerSlaveCommand("bazaar", Bazaar, command_version)
 
 
+class Bzr(SourceBase):
+    """bzr-specific VC operation. In addition to the arguments
+    handled by SourceBase, this command reads the following keys:
+
+    ['repourl'] (required): the Bzr repository string
+    """
+
+    header = "bzr operation"
+
+    def setup(self, args):
+        SourceBase.setup(self, args)
+        self.vcexe = getCommand("bzr")
+        self.repourl = args['repourl']
+        self.sourcedata = "%s\n" % self.repourl
+        self.revision = self.args.get('revision')
+
+    def sourcedirIsUpdateable(self):
+        if os.path.exists(os.path.join(self.builder.basedir,
+                                       self.srcdir, ".buildbot-patched")):
+            return False
+        if self.revision:
+            # checking out a specific revision requires a full 'bzr checkout'
+            return False
+        return os.path.isdir(os.path.join(self.builder.basedir,
+                                          self.srcdir, ".bzr"))
+
+    def doVCUpdate(self):
+        assert not self.revision
+        # update: possible for mode in ('copy', 'update')
+        srcdir = os.path.join(self.builder.basedir, self.srcdir)
+        command = [self.vcexe, 'update']
+        c = ShellCommand(self.builder, command, srcdir,
+                         sendRC=False, timeout=self.timeout)
+        self.command = c
+        return c.start()
+
+    def doVCFull(self):
+        # checkout or export
+        d = self.builder.basedir
+        if self.mode == "export":
+            # exporting in bzr requires a separate directory
+            return self.doVCExport()
+        # originally I added --lightweight here, but then 'bzr revno' is
+        # wrong. The revno reported in 'bzr version-info' is correct,
+        # however. Maybe this is a bzr bug?
+        #
+        # In addition, you cannot perform a 'bzr update' on a repo pulled
+        # from an HTTP repository that used 'bzr checkout --lightweight'. You
+        # get a "ERROR: Cannot lock: transport is read only" when you try.
+        #
+        # So I won't bother using --lightweight for now.
+
+        command = [self.vcexe, 'checkout']
+        if self.revision:
+            command.append('--revision')
+            command.append(str(self.revision))
+        command.append(self.repourl)
+        command.append(self.srcdir)
+
+        c = ShellCommand(self.builder, command, d,
+                         sendRC=False, timeout=self.timeout)
+        self.command = c
+        d = c.start()
+        return d
+
+    def doVCExport(self):
+        tmpdir = os.path.join(self.builder.basedir, "export-temp")
+        srcdir = os.path.join(self.builder.basedir, self.srcdir)
+        command = [self.vcexe, 'checkout', '--lightweight']
+        if self.revision:
+            command.append('--revision')
+            command.append(str(self.revision))
+        command.append(self.repourl)
+        command.append(tmpdir)
+        c = ShellCommand(self.builder, command, self.builder.basedir,
+                         sendRC=False, timeout=self.timeout)
+        self.command = c
+        d = c.start()
+        def _export(res):
+            command = [self.vcexe, 'export', srcdir]
+            c = ShellCommand(self.builder, command, tmpdir,
+                             sendRC=False, timeout=self.timeout)
+            self.command = c
+            return c.start()
+        d.addCallback(_export)
+        return d
+
+    def get_revision_number(self, out):
+        # it feels like 'bzr revno' sometimes gives different results than
+        # the 'revno:' line from 'bzr version-info', and the one from
+        # version-info is more likely to be correct.
+        for line in out.split("\n"):
+            colon = line.find(":")
+            if colon != -1:
+                key, value = line[:colon], line[colon+2:]
+                if key == "revno":
+                    return int(value)
+        raise ValueError("unable to find revno: in bzr output: '%s'" % out)
+
+    def parseGotRevision(self):
+        command = [self.vcexe, "version-info"]
+        c = ShellCommand(self.builder, command,
+                         os.path.join(self.builder.basedir, self.srcdir),
+                         environ=self.env,
+                         sendStdout=False, sendStderr=False, sendRC=False,
+                         keepStdout=True)
+        c.usePTY = False
+        d = c.start()
+        def _parse(res):
+            try:
+                return self.get_revision_number(c.stdout)
+            except ValueError:
+                msg =("Bzr.parseGotRevision unable to parse output "
+                      "of bzr version-info: '%s'" % c.stdout.strip())
+                log.msg(msg)
+                self.sendStatus({'header': msg + "\n"})
+                return None
+        d.addCallback(_parse)
+        return d
+
+registerSlaveCommand("bzr", Bzr, command_version)
+
 class Mercurial(SourceBase):
     """Mercurial specific VC operation. In addition to the arguments
     handled by SourceBase, this command reads the following keys:





More information about the Commits mailing list