[Buildbot-commits] buildbot/buildbot/steps shell.py,1.10,1.11

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


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

Modified Files:
	shell.py 
Log Message:
[project @ #115:Make-WithProperties-easier-to-use-internally.patch]
Patch by Greg Ward <gerg.ward+buildbot at gmail.com>:
Make WithProperties easier to use internally by factoring out function
render().

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

Index: shell.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/shell.py,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- shell.py	18 Mar 2008 20:06:12 -0000	1.10
+++ shell.py	20 Mar 2008 23:56:41 -0000	1.11
@@ -39,6 +39,19 @@
             s = self.fmtstring % _BuildPropertyDictionary(build)
         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)
+
 class ShellCommand(LoggingBuildStep):
     """I run a single shell command on the buildslave. I return FAILURE if
     the exit code of that command is non-zero, SUCCESS otherwise. To change
@@ -159,40 +172,20 @@
             return ["'%s" % words[0], "%s'" % words[1]]
         return ["'%s" % words[0], "%s" % words[1], "...'"]
 
-
-    def _interpolateProperties(self, value):
-        """
-        Expand the L{WithProperties} objects in L{value}
-        """
-        if isinstance(value, types.StringTypes) or \
-           isinstance(value, types.BooleanType) or \
-           isinstance(value, types.IntType) or \
-           isinstance(value, types.FloatType):
-            return value
-
-        if isinstance(value, types.ListType):
-            return [self._interpolateProperties(val) for val in value]
-
-        if isinstance(value, types.TupleType):
-            return tuple([self._interpolateProperties(val) for val in value])
-
-        if isinstance(value, types.DictType):
-            new_dict = { }
-            for key, val in value.iteritems():
-                new_key = self._interpolateProperties(key)
-                new_dict[new_key] = self._interpolateProperties(val)
-            return new_dict
-
-        # To make sure we catch anything we forgot
-        assert isinstance(value, WithProperties), \
-               "%s (%s) is not a WithProperties" % (value, type(value))
-
-        return value.render(self.build)
+    def _interpolateProperties(self, command):
+        # interpolate any build properties into our command
+        if not isinstance(command, (list, tuple)):
+            return command
+        command_argv = []
+        for argv in command:
+            if isinstance(argv, WithProperties):
+                command_argv.append(argv.render(self.build))
+            else:
+                command_argv.append(argv)
+        return command_argv
 
     def _interpolateWorkdir(self, workdir):
-        if isinstance(workdir, WithProperties):
-            return workdir.render(self.build)
-        return workdir
+        return render(workdir, self.build)
 
     def setupEnvironment(self, cmd):
         # merge in anything from Build.slaveEnvironment . Earlier steps





More information about the Commits mailing list