[Buildbot-commits] buildbot/buildbot/process buildstep.py,1.8,1.9

Brian Warner warner at users.sourceforge.net
Thu Mar 20 23:56:56 UTC 2008


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

Modified Files:
	buildstep.py 
Log Message:
[project @ #115:Move-WithProperties-and-friends.patch]
Patch by Greg Ward <gerg.ward+buildbot at gmail.com>:
Move WithProperties and friends (render(), _BuildPropertyMapping)
from buildbot.steps.shell to buildbot.process.buildstep.

Original author: dustin at v.igoro.us
Date: 2008-03-13 03:11:52+00:00

Index: buildstep.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/process/buildstep.py,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- buildstep.py	12 Aug 2007 22:22:41 -0000	1.8
+++ buildstep.py	20 Mar 2008 23:56:53 -0000	1.9
@@ -8,6 +8,7 @@
 from twisted.python.failure import Failure
 from twisted.web.util import formatFailure
 
+from buildbot import util
 from buildbot import interfaces
 from buildbot.status import progress
 from buildbot.status.builder import SUCCESS, WARNINGS, FAILURE, SKIPPED, \
@@ -1082,3 +1083,46 @@
         self.step_status.setText(self.getText(cmd, results))
         self.step_status.setText2(self.maybeGetText2(cmd, results))
 
+class _BuildPropertyMapping:
+    def __init__(self, build):
+        self.build = build
+    def __getitem__(self, name):
+        p = self.build.getProperty(name)
+        if p is None:
+            p = ""
+        return p
+
+class WithProperties(util.ComparableMixin):
+    """This is a marker class, used in ShellCommand's command= argument to
+    indicate that we want to interpolate a build property.
+    """
+
+    compare_attrs = ('fmtstring', 'args')
+
+    def __init__(self, fmtstring, *args):
+        self.fmtstring = fmtstring
+        self.args = args
+
+    def render(self, build):
+        pmap = _BuildPropertyMapping(build)
+        if self.args:
+            strings = []
+            for name in self.args:
+                strings.append(pmap[name])
+            s = self.fmtstring % tuple(strings)
+        else:
+            s = self.fmtstring % pmap
+        return s
+
+def render(s, build):
+    """Return a string based on s and build that is suitable for use
+    in a running BuildStep.  If s is a string, return s.  If s is a
+    WithProperties object, return the result of s.render(build).
+    Otherwise, return str(s).
+    """
+    if isinstance(s, (str, unicode)):
+        return s
+    elif isinstance(s, WithProperties):
+        return s.render(build)
+    else:
+        return str(s)





More information about the Commits mailing list