Commit 0fe3a21c authored by Bryton Lacquement's avatar Bryton Lacquement 🚪 Committed by Julien Muchembled

default: new 'init' option

The purpose is to replace colletive.recipe.shelloutput

/reviewed-on !11
parent 008302f0
Pipeline #8118 passed with stage
in 0 seconds
......@@ -4,12 +4,13 @@
.. contents::
Examples
--------
Default
-------
Recipe to build the software.
The default recipe can be used to execute ad-hoc Python code at both
init & install phases.
Example buildout::
Example buildout that builds software::
[buildout]
parts =
......@@ -83,6 +84,19 @@ For example::
print('%(foo)s')
# will print “%(foo)s”
Using the init option::
[section-one]
recipe = slapos.recipe.build
init =
import os
options['foo'] = os.uname()[4]
[section-two]
bar = ${section-one:foo}
It is also possible to use both `init` & `script` in the same section.
Pure download
~~~~~~~~~~~~~
......
......@@ -268,18 +268,28 @@ class Script(EnvironMixin):
except KeyError:
self.options['location'] = os.path.join(
buildout['buildout']['parts-directory'], self.name)
self.script = self.options['script']
format = options.get('format', 'yes') in TRUE_LIST
init = options.get('init')
self.script = options.get('script')
if self.script:
if self.options.get('format', 'yes') in TRUE_LIST:
if format:
self.script = self.script % self.options
elif not init:
raise zc.buildout.UserError('either init or script is required')
if self.options.get('keep-on-error', '').strip().lower() in TRUE_LIST:
self.logger.debug('Keeping directories in case of errors')
self.keep_on_error = True
else:
self.keep_on_error = False
EnvironMixin.__init__(self, False)
if init:
if format:
init = init % options
exec(init, {'self': self, 'options': options, 'env': self.environ})
def install(self):
if not self.script:
return ""
location = self.options['location']
if os.path.lexists(location):
self.logger.warning('Removing already existing path %r', location)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment