Skip to content

Commit

Permalink
Better stripping of properties in describe before rendering
Browse files Browse the repository at this point in the history
This function is still an awful mess, but this replicates the
circumstances of #2368 in a test and fixes it.  Refs #2368.
  • Loading branch information
djmitche committed Sep 17, 2012
1 parent 78db42a commit fa538ab
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
33 changes: 18 additions & 15 deletions master/buildbot/steps/shell.py
Expand Up @@ -147,10 +147,11 @@ def setCommand(self, command):

def _flattenList(self, mainlist, commands):
for x in commands:
if isinstance(x, (str, unicode)):
mainlist.append(x)
elif x != []:
self._flattenList(mainlist, x)
if isinstance(x, (list, tuple)):
if x != []:
self._flattenList(mainlist, x)
else:
mainlist.append(x)

def describe(self, done=False):
desc = self._describe(done)
Expand Down Expand Up @@ -197,20 +198,22 @@ def _describe(self, done=False):
# WithProperties and Property don't have __len__
return ["???"]

# flatten any nested lists
tmp = []
for x in words:
if isinstance(x, (str, unicode)):
tmp.append(x)
else:
self._flattenList(tmp, x)
self._flattenList(tmp, words)
words = tmp

# strip instances and other detritus (which can happen if a
# description is requested before rendering)
words = [ w for w in words if isinstance(w, (str, unicode)) ]

if len(tmp) < 1:
if len(words) < 1:
return ["???"]
if len(tmp) == 1:
return ["'%s'" % tmp[0]]
if len(tmp) == 2:
return ["'%s" % tmp[0], "%s'" % tmp[1]]
return ["'%s" % tmp[0], "%s" % tmp[1], "...'"]
if len(words) == 1:
return ["'%s'" % words[0]]
if len(words) == 2:
return ["'%s" % words[0], "%s'" % words[1]]
return ["'%s" % words[0], "%s" % words[1], "...'"]

except:
log.err(failure.Failure(), "Error describing step")
Expand Down
6 changes: 6 additions & 0 deletions master/buildbot/test/unit/test_steps_shell.py
Expand Up @@ -151,6 +151,12 @@ def test_describe_unrendered_WithProperties(self):
self.assertEqual((step.describe(), step.describe(done=True)),
(['???'],)*2)

def test_describe_unrendered_WithProperties_list(self):
step = shell.ShellCommand(
command=[ 'x', properties.WithProperties(''), 'y' ])
self.assertEqual((step.describe(), step.describe(done=True)),
(["'x", "y'"],)*2)

@compat.usesFlushLoggedErrors
def test_describe_fail(self):
step = shell.ShellCommand(command=object())
Expand Down

0 comments on commit fa538ab

Please sign in to comment.