Discussion:
[Buildbot-devel] doStepIf function
robert dugal
2010-05-10 12:33:46 UTC
Permalink
I cannot figure out the syntax for how to use doStepIf with a function so that the step is only executed if certain conditions are true. The condition needs to have some complex testing of builder properties so I want to write this as a function.
How do I convert something like this below into using a function?

self.addStep(ShellCommand(
doStepIf=(
(lambda(step): step.build.getProperties().has_key("FOO"))
and

(lambda(step): step.getProperty("FOO") in fooList)
), command='some command'))


Rob


_________________________________________________________________
30 days of prizes to be won with Hotmail. Enter Here.
http://go.microsoft.com/?linkid=9729709
Charles Lepple
2010-05-10 13:01:29 UTC
Permalink
Post by robert dugal
I cannot figure out the syntax for how to use doStepIf with a
function so that the step is only executed if certain conditions are
true. The condition needs to have some complex testing of builder
properties so I want to write this as a function.
How do I convert something like this below into using a function?
self.addStep(ShellCommand(
doStepIf=(
step.build.getProperties().has_key("FOO"))
and
(lambda(step): step.getProperty("FOO") in fooList)
), command='some command'))
Something like this:

#########

def do_step_test(step):
return step.build.getProperties().has_key("FOO") and
step.getProperty("FOO") in fooList

self.addStep(ShellCommand(
doStepIf = do_step_test,
command = 'some command')

#########

To make that work with lambda functions, I think you would need to put
the "and" inside a single lambda expression. The boolean "and" of two
function definitions won't get you what you want (not to be confused
with the *results* of two functions, "and"ed together).

http://docs.python.org/tutorial/controlflow.html#lambda-forms
Alexander O'Donovan-Jones
2010-05-26 11:23:35 UTC
Permalink
Since people have been talking about this, does anyone know the syntax to query the result of a previous step?
Something like:

def doStepIf(step):
return step.build.previousStep.getResults()

I'm banging my head trying to work out the correct way to climb the ladder to get this information :S

-----Original Message-----
From: Charles Lepple [mailto:***@gmail.com]
Sent: Monday, May 10, 2010 1:01 PM
To: robert dugal
Cc: buildbot-devel
Subject: Re: [Buildbot-devel] doStepIf function
Post by robert dugal
I cannot figure out the syntax for how to use doStepIf with a
function so that the step is only executed if certain conditions are
true. The condition needs to have some complex testing of builder
properties so I want to write this as a function.
How do I convert something like this below into using a function?
self.addStep(ShellCommand(
doStepIf=(
step.build.getProperties().has_key("FOO"))
and
(lambda(step): step.getProperty("FOO") in fooList)
), command='some command'))
Something like this:

#########

def do_step_test(step):
return step.build.getProperties().has_key("FOO") and
step.getProperty("FOO") in fooList

self.addStep(ShellCommand(
doStepIf = do_step_test,
command = 'some command')

#########

To make that work with lambda functions, I think you would need to put
the "and" inside a single lambda expression. The boolean "and" of two
function definitions won't get you what you want (not to be confused
with the *results* of two functions, "and"ed together).

http://docs.python.org/tutorial/controlflow.html#lambda-forms

------------------------------------------------------------------------------
r***@hotmail.com
2010-05-26 11:39:55 UTC
Permalink
I have set properties in previous step(s) then the doStepIf function checks
if those properties have specific values.

--------------------------------------------------
From: "Alexander O'Donovan-Jones" <***@ccpgames.com>
Sent: Wednesday, May 26, 2010 7:23 AM
To: "Charles Lepple" <***@gmail.com>; "robert dugal"
<***@hotmail.com>
Cc: "buildbot-devel" <buildbot-***@lists.sourceforge.net>
Subject: RE: [Buildbot-devel] doStepIf function
Post by Alexander O'Donovan-Jones
Since people have been talking about this, does anyone know the syntax to
query the result of a previous step?
return step.build.previousStep.getResults()
I'm banging my head trying to work out the correct way to climb the ladder
to get this information :S
-----Original Message-----
Sent: Monday, May 10, 2010 1:01 PM
To: robert dugal
Cc: buildbot-devel
Subject: Re: [Buildbot-devel] doStepIf function
Post by robert dugal
I cannot figure out the syntax for how to use doStepIf with a
function so that the step is only executed if certain conditions are
true. The condition needs to have some complex testing of builder
properties so I want to write this as a function.
How do I convert something like this below into using a function?
self.addStep(ShellCommand(
doStepIf=(
step.build.getProperties().has_key("FOO"))
and
(lambda(step): step.getProperty("FOO") in fooList)
), command='some command'))
#########
return step.build.getProperties().has_key("FOO") and
step.getProperty("FOO") in fooList
self.addStep(ShellCommand(
doStepIf = do_step_test,
command = 'some command')
#########
To make that work with lambda functions, I think you would need to put
the "and" inside a single lambda expression. The boolean "and" of two
function definitions won't get you what you want (not to be confused
with the *results* of two functions, "and"ed together).
http://docs.python.org/tutorial/controlflow.html#lambda-forms
------------------------------------------------------------------------------
_______________________________________________
Buildbot-devel mailing list
https://lists.sourceforge.net/lists/listinfo/buildbot-devel
Alexander O'Donovan-Jones
2010-05-26 12:08:21 UTC
Permalink
Ah, finally managed to work it out. Some context: I wish to send an email if a particular step failed, with relevant information.

###########

from buildbot.status.builder import Results, SUCCESS

def doStepIf(step):
allSteps = step.build.getStatus().getSteps()
firstStep = allSteps[0]
rc = firstStep.getResults()[0] # returns a tuple of (rc, string)
# if the rc == SUCCESS then don't continue, since we don't want to run this step
return Results[rc] == Results[SUCCESS]

###########

-----Original Message-----
From: ***@hotmail.com [mailto:***@hotmail.com]
Sent: Wednesday, May 26, 2010 11:40 AM
To: Alexander O'Donovan-Jones; Charles Lepple
Cc: buildbot-devel
Subject: Re: [Buildbot-devel] doStepIf function

I have set properties in previous step(s) then the doStepIf function checks
if those properties have specific values.

--------------------------------------------------
From: "Alexander O'Donovan-Jones" <***@ccpgames.com>
Sent: Wednesday, May 26, 2010 7:23 AM
To: "Charles Lepple" <***@gmail.com>; "robert dugal"
<***@hotmail.com>
Cc: "buildbot-devel" <buildbot-***@lists.sourceforge.net>
Subject: RE: [Buildbot-devel] doStepIf function
Post by Alexander O'Donovan-Jones
Since people have been talking about this, does anyone know the syntax to
query the result of a previous step?
return step.build.previousStep.getResults()
I'm banging my head trying to work out the correct way to climb the ladder
to get this information :S
-----Original Message-----
Sent: Monday, May 10, 2010 1:01 PM
To: robert dugal
Cc: buildbot-devel
Subject: Re: [Buildbot-devel] doStepIf function
Post by robert dugal
I cannot figure out the syntax for how to use doStepIf with a
function so that the step is only executed if certain conditions are
true. The condition needs to have some complex testing of builder
properties so I want to write this as a function.
How do I convert something like this below into using a function?
self.addStep(ShellCommand(
doStepIf=(
step.build.getProperties().has_key("FOO"))
and
(lambda(step): step.getProperty("FOO") in fooList)
), command='some command'))
#########
return step.build.getProperties().has_key("FOO") and
step.getProperty("FOO") in fooList
self.addStep(ShellCommand(
doStepIf = do_step_test,
command = 'some command')
#########
To make that work with lambda functions, I think you would need to put
the "and" inside a single lambda expression. The boolean "and" of two
function definitions won't get you what you want (not to be confused
with the *results* of two functions, "and"ed together).
http://docs.python.org/tutorial/controlflow.html#lambda-forms
------------------------------------------------------------------------------
_______________________________________________
Buildbot-devel mailing list
https://lists.sourceforge.net/lists/listinfo/buildbot-devel
------------------------------------------------------------------------------
Greg Ward
2010-05-13 17:51:18 UTC
Permalink
Post by robert dugal
I cannot figure out the syntax for how to use doStepIf with a function so
that the step is only executed if certain conditions are true. The condition
needs to have some complex testing of builder properties so I want to write
this as a function.
How do I convert something like this below into using a function?
           self.addStep(ShellCommand(
                doStepIf=(
                (lambda(step): step.build.getProperties().has_key("FOO"))
                and
                (lambda(step): step.getProperty("FOO") in fooList)
                ), command='some command'))
Charles Lepple's answer is what you want. Here's what you actually did:

func1 = lambda step: step.build.getProperties().has_key("FOO")
func2 = lambda step: lambda(step): step.getProperty("FOO") in fooList)
func = func1 and func2
self.addStep(ShellCommand(
doStepIf=func,
...
))

Since func1 and func2 are both true values, "func1 and func2"
evaluates to func1. So your func2 is unused.

You *can* do this in a single lambda, but you really don't want to.
Charles' suggestion is the way to go.

Greg
Loading...