Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Buildout recipes to execute Python or Shell scripts

Project description

This module implements two simple recipes to execute either a shell script (actually batch scripts under M$-Windows) or a Python script.

Both recipes take two options, install and update: both are considered as a list of statements, one per line, that will be written in a temporary file that will be executed respectively when the recipe is installed or updated. One or the other may be missing, and in such case nothing will happen for that particular step.

When the commands to execute depend on the platform, they can be specified using the options install-linux or install-win32 that have higher priority than the generic form.

Shell scripts

The metapensiero.recipe.script:shell recipe is implemented by the ShellScript class, and can be used in the following way:

recipe = metapensiero.recipe.script:shell
ini = config.ini
install = ${buildout:bin-directory}/soladmin create-config ${:ini}

As said, some time the commands to execute depend on the particular platform they are run. In such cases, you can say:

recipe = metapensiero.recipe.script:shell
ini = config.ini
install = ${buildout:bin-directory}/soladmin create-config ${:ini}
install-win32 =
   ${buildout:bin-directory}/soladmin create-config ${:ini}
   echo Configuration created!

Python scripts

The metapensiero.recipe.script:python recipe is implemented by the PythonScript class. It is somewhat more powerful because it can easily access the whole buildout configuration.

Consider the following example:

recipe = metapensiero.recipe.script:python
install =
  >>> import sys
  >>> from os.path import join
  >>> basedir = buildout['buildout']['directory']
  >>> bindir = buildout['buildout']['bin-directory']
  >>> script = join(basedir, 'sol.bat' if sys.platform=='win32' else '')
  >>> config = join(basedir, buildout['config']['ini'])
  >>> with open(script, 'w') as f:
  >>>   if sys.platform == 'win32':
  >>>     f.write('@echo off\n')
  >>>   f.write('%s %s\n' % (join(bindir, 'solserver'), config))
  >>> installed = script

As you can see, the script can access other section settings thru the buildout local variable, a dictionary that contains the whole buildout configuration. Another local variable is options, another dictionary containing the recipe settings.

The script may set the installed variable, that can be either a simple scalar string value or a sequence of strings: it will be used as the result of the recipe, which usually is the list of the files/directories installed by the recipe itself that will be deleted whenever the recipe is removed from the configuration.

Using eggs

If the Python script uses additional eggs, they can be specified with the eggs option, like in the following example:

recipe = metapensiero.recipe.script:python
eggs = metapensiero.extjs.desktop
install =
  >>> from metapensiero.extjs.desktop.scripts.extjs_dl import download_and_extract, URL
  >>> download_and_extract(URL)


1.2 (2014-03-08)

  • Simple test suite
  • Fix return of installed stuff in Python scripts

1.1 (2014-03-08)

  • First release on PyPI

1.0 (2014-03-08)

  • Initial version, extracted from SoLista

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
metapensiero.recipe.script-1.2.tar.gz (6.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page