Skip to main content

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:

[config]
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:

[config]
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!
   pause

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:

[start_script]
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 'sol.sh')
  >>> 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:

[extjs]
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)

Changes

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.

Source Distribution

metapensiero.recipe.script-1.2.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file metapensiero.recipe.script-1.2.tar.gz.

File metadata

File hashes

Hashes for metapensiero.recipe.script-1.2.tar.gz
Algorithm Hash digest
SHA256 811ca69f62561d9cecb6597de169766225593bf1337cff390f95f1b966f876d8
MD5 a124b9c4f706cef3c5b34d15d9654078
BLAKE2b-256 ede2da1a638e6b0ec28083f09d645f71cd8390552798830028b809af382da193

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page