[Buildbot-commits] buildbot/buildbot/steps shell.py,1.9,1.10
Brian Warner
warner at users.sourceforge.net
Tue Mar 18 20:06:14 UTC 2008
Update of /cvsroot/buildbot/buildbot/buildbot/steps
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv24387/buildbot/steps
Modified Files:
shell.py
Log Message:
[project @ shell.py: allow WithProperties in environment variables and workdir=. Closes #52.]
Original author: warner at lothar.com
Date: 2008-03-18 20:02:24+00:00
Index: shell.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/shell.py,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- shell.py 23 Dec 2007 08:35:31 -0000 1.9
+++ shell.py 18 Mar 2008 20:06:12 -0000 1.10
@@ -148,8 +148,7 @@
if self.description is not None:
return self.description
- words = self.command
- # TODO: handle WithProperties here
+ words = self._interpolateProperties(self.command)
if isinstance(words, types.StringTypes):
words = words.split()
if len(words) < 1:
@@ -160,17 +159,35 @@
return ["'%s" % words[0], "%s'" % words[1]]
return ["'%s" % words[0], "%s" % words[1], "...'"]
- 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 _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 _interpolateWorkdir(self, workdir):
if isinstance(workdir, WithProperties):
@@ -186,7 +203,7 @@
if slaveEnv:
if cmd.args['env'] is None:
cmd.args['env'] = {}
- cmd.args['env'].update(slaveEnv)
+ cmd.args['env'].update(self._interpolateProperties(slaveEnv))
# note that each RemoteShellCommand gets its own copy of the
# dictionary, so we shouldn't be affecting anyone but ourselves.
@@ -219,7 +236,7 @@
command = self._interpolateProperties(self.command)
assert isinstance(command, (list, tuple, str))
# create the actual RemoteShellCommand instance now
- kwargs = self.remote_kwargs
+ kwargs = self._interpolateProperties(self.remote_kwargs)
kwargs['workdir'] = self._interpolateWorkdir(kwargs['workdir'])
kwargs['command'] = command
kwargs['logfiles'] = self.logfiles
More information about the Commits
mailing list