[Buildbot-devel] Dynamically updating text displayed in build step status
warner-buildbot at lothar.com
Wed Apr 19 04:26:55 UTC 2006
[sorry for taking so long to respond.. poor Grig had to remind me several
times about this one]
> From: Grig Gheorghiu <grig at gheorghiu.net>
> I've been trying to find ways to dynamically update the text that is
> displayed in the build step status in the HTML Waterfall page.
> However, I also wanted to be able to display a piece of information
> (such as a version number) that was computed by the slave running that
> build step.
> def getText(self, cmd, results):
> text = self.describe(True)
> for elem in text:
> if re.search("version", elem):
> return text
> if results == WARNINGS:
> text += ["warnings"]
> if results == FAILURE:
> text += ["failed"]
> if self.version:
> text += ["version=" + self.version]
> return text
The problem here is that self.describe() is returning a list of strings, but
it isn't expecting anyone to mutate it. When you do 'text += ["warnings"]',
you're actually changing the class-wide value, which is why you see multiple
copies of the same text showing up later. (python expands 'l1 += l2' into
'l1.extend(l2)', which modifies l1 in place).
Instead, try something like this:
def getText(self, cmd, results):
text = self.describe(True)
if results == WARNINGS:
text = text + ["warnings"]
if results == FAILURE:
text = text + ["failed"]
text = text + ["version=" + self.version]
Each one of those 'text = text + ' statements will create a brand-new list,
so the original description is left unmodified.
> Question: am I on the right track here, or am I needlessly complicating
> my life?
This seems like a perfectly reasonable way to change the text based upon the
results of the step. You just ran into a slightly subtle python gotcha :).
More information about the devel