gs.recipe.base
¶
This product supplies the gs.recipe.base.Recipe
abstract base class. It provides some useful methods that
make writing zc.buildout
recipes easier.
Contents:
gs.recipe.base
API Reference¶
Currently this module only supplies the
gs.recipe.base.Recipe
abstract base class.
-
class
gs.recipe.base.
Recipe
(buildout, name, options)[source]¶ Recipe abstract base class.
Parameters: Raises: - ValueError – If
buildout['buildout']
is missing - ValueError – If
buildout['buildout']['directory']
is missing - ValueError – If
buildout['buildout']['bin-directory']
is missing
Normally
zc.buildout
handles passing the correct values tobuildout
,name
, andoptions
. As a result conformance is not as hard as it looks from the signature of the__init__
.Concrete implementations of this base class must implement the
install()
method, and theupdate()
method.-
install
()[source]¶ A concrete implementation of this method should call the following.
should_run()
to determine if the recipe should run at all.mark_locked()
to lock the recipe after it has run.
-
mark_locked
()[source]¶ Create a lock file for the recipe.
Returns: None
A lock-file is used to record that a recipe has already been run, and it should be skipped. The presence or absence of the fille is important, rather than the contents of the file.
-
should_run
()[source]¶ Determine if the recipe should be run.
Returns: True
if the recipe should be run,False
otherwise.Return type: bool
A recipe should be run in two possible scenarios.
- The
run-once
buildout option is set to false, off, or no. - The
run-once
is absent — or set to any value other than false, off or no — and the lock-file that is created by themark_locked()
method is absent.
As a side effect, a message is displayed to
sys.stdout
ifshould_run()
returnsFalse
. This message tells the administrator how to force the recipe to be run.- The
- ValueError – If
Example¶
In the following example the concrete class SetupGSRecipe
implements the install
method. It calls should_run
to
determine if the recipe should be run at all, and
calls mark_locked
once it is done.
from gs.recipe.base import Recipe
class SetupGSRecipe(Recipe):
def get_script_command(self):
'Get the command to do stuff'
def install(self):
if self.should_run():
command = self.get_script_command()
try:
retcode = subprocess.call(command, shell=True)
if retcode == 0:
self.mark_locked()
sys.stdout.write('GroupServer site created\n\n')
else:
m = '{0}: Issue running\n\t{1}\nReturned {2}\n'
msg = m.format(self.name, command, retcode)
raise UserError(msg)
except OSError as e:
m = '{0}: Failed to run\n\t{1}\n{2}\n'
msg = m.format(self.name, command, e)
raise UserError(msg)
return tuple()
def update(self):
self.install()
Resources¶
- Code repository: https://source.iopen.net/groupserver/gs.group.recipe.base
- Questions and comments to http://groupserver.org/groups/development
- Report bugs at https://redmine.iopen.net/projects/groupserver