Skip to content

Instantly share code, notes, and snippets.

@gsemet
Last active August 29, 2015 14:12
Show Gist options
  • Save gsemet/1294d62cd2987782cac9 to your computer and use it in GitHub Desktop.
Save gsemet/1294d62cd2987782cac9 to your computer and use it in GitHub Desktop.
# renderables ('Agreation' solution)
@any_kind_of_decorator_to_declare_a_renderable_pre_init
def commandRenderable1(prop):
# A renderable cannot access to the self of a step, since it is evaluated before the actual initialization. So it cannot change the "self" state, and cannot add step logs
...
a = prop.getProperty('aproperty')
...
return the_actual_commands_to_add
@any_kind_of_decorator_to_declare_a_renderable_post_init
def commandRenderable2(self):
# This renderable can access to the self of a step, since it is evaluated **after**initialization.
# So it can change the "self" state, and cannot add step logs
...
a = self.getProperty('aproperty')
self.addLogStdio("blablabla")
...
return the_actual_commands_to_add
@any_kind_of_decorator_to_declare_a_renderable_post_execution # is it really needed ?
def postExecute(self, res):
# This renderable can access to the self of a step and access to every member it needs to to do its job
# it is evaluated AFTER the step execution.
# So it can change the "self" state (modification is useless), and can add step logs, upload files to location,...
...
if res == FAILURE and some_reason:
res = WARNINGS
return res
steps.append(BuildStep(command=commandRenderable[1/2/3],
postExecute=postExecute))
# 'Inheritance' Solution
class TheSpecialBuildStep(BuildStep):
def command(self):
# not the same signature than the renderable, but same name.
# it has the self so can change the state of the step directly even if it is not advises.
# it can add logs
...
a = self.getProperty('aproperty')
self.addLogStdio("I can describe what I will do since I have self").
self.some_variable = some_value
...
return the_actual_commands_to_add
def postExecute(self, res):
if res == FAILURE and some_reason:
res = WARNINGS
return res
steps.append(TheSpecialBuildStep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment