[Buildbot-commits] buildbot/buildbot/steps python.py, 1.5, 1.6 shell.py, 1.21, 1.22 source.py, 1.13, 1.14 transfer.py, 1.13, 1.14

Brian Warner warner at users.sourceforge.net
Thu May 22 22:12:59 UTC 2008


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

Modified Files:
	python.py shell.py source.py transfer.py 
Log Message:
[project @ #124:properties-class.patch]
Add and use a Properties class, refactor the way properties are rendered,
and update unit tests accordingly.

Original author: dustin at v.igoro.us
Date: 2008-04-12 20:58:59+00:00

Index: python.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/python.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- python.py	5 Oct 2006 00:45:48 -0000	1.5
+++ python.py	22 May 2008 22:12:57 -0000	1.6
@@ -96,8 +96,8 @@
             if counts[m]:
                 self.descriptionDone.append("%s=%d" % (m, counts[m]))
                 self.addCompleteLog(m, "".join(summaries[m]))
-            self.setProperty("pyflakes-%s" % m, counts[m])
-        self.setProperty("pyflakes-total", sum(counts.values()))
+            self.setProperty("pyflakes-%s" % m, counts[m], "pyflakes")
+        self.setProperty("pyflakes-total", sum(counts.values()), "pyflakes")
 
 
     def evaluateCommand(self, cmd):

Index: shell.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/shell.py,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- shell.py	22 May 2008 22:12:46 -0000	1.21
+++ shell.py	22 May 2008 22:12:57 -0000	1.22
@@ -2,12 +2,12 @@
 
 import re
 from twisted.python import log
-from buildbot.process.buildstep import LoggingBuildStep, RemoteShellCommand, \
-     render_properties
+from buildbot.process.buildstep import LoggingBuildStep, RemoteShellCommand
 from buildbot.status.builder import SUCCESS, WARNINGS, FAILURE
 
-# for existing configurations that import WithProperties from here
-from buildbot.process.buildstep import WithProperties
+# for existing configurations that import WithProperties from here.  We like
+# to move this class around just to keep our readers guessing.
+from buildbot.process.properties import WithProperties
 
 class ShellCommand(LoggingBuildStep):
     """I run a single shell command on the buildslave. I return FAILURE if
@@ -118,11 +118,12 @@
         if self.description is not None:
             return self.description
 
+        properties = self.build.getProperties()
         words = self.command
         if isinstance(words, (str, unicode)):
             words = words.split()
         # render() each word to handle WithProperties objects
-        words = [render_properties(word, self.build) for word in words]
+        words = [properties.render(word) for word in words]
         if len(words) < 1:
             return ["???"]
         if len(words) == 1:
@@ -131,45 +132,18 @@
             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, (str, unicode, bool, int, float, type(None))):
-            return value
-
-        if isinstance(value, list):
-            return [self._interpolateProperties(val) for val in value]
-
-        if isinstance(value, tuple):
-            return tuple([self._interpolateProperties(val) for val in value])
-
-        if isinstance(value, dict):
-            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):
-        return render_properties(workdir, self.build)
-
     def setupEnvironment(self, cmd):
+        # XXX is this used? documented? replaced by properties?
         # merge in anything from Build.slaveEnvironment . Earlier steps
         # (perhaps ones which compile libraries or sub-projects that need to
         # be referenced by later steps) can add keys to
         # self.build.slaveEnvironment to affect later steps.
+        properties = self.build.getProperties()
         slaveEnv = self.build.slaveEnvironment
         if slaveEnv:
             if cmd.args['env'] is None:
                 cmd.args['env'] = {}
-            cmd.args['env'].update(self._interpolateProperties(slaveEnv))
+            cmd.args['env'].update(properties.render(slaveEnv))
             # note that each RemoteShellCommand gets its own copy of the
             # dictionary, so we shouldn't be affecting anyone but ourselves.
 
@@ -199,12 +173,11 @@
         # this block is specific to ShellCommands. subclasses that don't need
         # to set up an argv array, an environment, or extra logfiles= (like
         # the Source subclasses) can just skip straight to startCommand()
-        command = self._interpolateProperties(self.command)
-        assert isinstance(command, (list, tuple, str))
+        properties = self.build.getProperties()
+
         # create the actual RemoteShellCommand instance now
-        kwargs = self._interpolateProperties(self.remote_kwargs)
-        kwargs['workdir'] = self._interpolateWorkdir(kwargs['workdir'])
-        kwargs['command'] = command
+        kwargs = properties.render(self.remote_kwargs)
+        kwargs['command'] = properties.render(self.command)
         kwargs['logfiles'] = self.logfiles
         cmd = RemoteShellCommand(**kwargs)
         self.setupEnvironment(cmd)
@@ -224,7 +197,7 @@
         m = re.search(r'^(\d+)', out)
         if m:
             self.kib = int(m.group(1))
-            self.setProperty("tree-size-KiB", self.kib)
+            self.setProperty("tree-size-KiB", self.kib, "treesize")
 
     def evaluateCommand(self, cmd):
         if cmd.rc != 0:
@@ -298,7 +271,7 @@
             old_count = self.getProperty("warnings-count")
         except KeyError:
             old_count = 0
-        self.setProperty("warnings-count", old_count + self.warnCount)
+        self.setProperty("warnings-count", old_count + self.warnCount, "WarningCountingShellCommand")
 
 
     def evaluateCommand(self, cmd):

Index: source.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/source.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- source.py	29 Apr 2008 20:21:36 -0000	1.13
+++ source.py	22 May 2008 22:12:57 -0000	1.14
@@ -187,7 +187,7 @@
         got_revision = None
         if cmd.updates.has_key("got_revision"):
             got_revision = str(cmd.updates["got_revision"][-1])
-        self.setProperty("got_revision", got_revision)
+        self.setProperty("got_revision", got_revision, "source")
 
 
 

Index: transfer.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/steps/transfer.py,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- transfer.py	21 Mar 2008 03:53:36 -0000	1.13
+++ transfer.py	22 May 2008 22:12:57 -0000	1.14
@@ -4,8 +4,7 @@
 from twisted.internet import reactor
 from twisted.spread import pb
 from twisted.python import log
-from buildbot.process.buildstep import RemoteCommand, BuildStep, \
-     render_properties
+from buildbot.process.buildstep import RemoteCommand, BuildStep
 from buildbot.process.buildstep import SUCCESS, FAILURE
 from buildbot.interfaces import BuildSlaveTooOldError
 
@@ -111,12 +110,14 @@
 
     def start(self):
         version = self.slaveVersion("uploadFile")
+        properties = self.build.getProperties()
+
         if not version:
             m = "slave is too old, does not know about uploadFile"
             raise BuildSlaveTooOldError(m)
 
-        source = render_properties(self.slavesrc, self.build)
-        masterdest = render_properties(self.masterdest, self.build)
+        source = properties.render(self.slavesrc)
+        masterdest = properties.render(self.masterdest)
         # we rely upon the fact that the buildmaster runs chdir'ed into its
         # basedir to make sure that relative paths in masterdest are expanded
         # properly. TODO: maybe pass the master's basedir all the way down
@@ -237,6 +238,8 @@
         self.mode = mode
 
     def start(self):
+        properties = self.build.getProperties()
+
         version = self.slaveVersion("downloadFile")
         if not version:
             m = "slave is too old, does not know about downloadFile"
@@ -244,9 +247,8 @@
 
         # we are currently in the buildmaster's basedir, so any non-absolute
         # paths will be interpreted relative to that
-        source = os.path.expanduser(render_properties(self.mastersrc,
-                                                      self.build))
-        slavedest = render_properties(self.slavedest, self.build)
+        source = os.path.expanduser(properties.render(self.mastersrc))
+        slavedest = properties.render(self.slavedest)
         log.msg("FileDownload started, from master %r to slave %r" %
                 (source, slavedest))
 





More information about the Commits mailing list