ZC Buildout recipe to execute a commande line in it's own shell
Project description
=====================
cp.recipe.cmd package
=====================
.. contents::
What is cp.recipe.cmd ?
=======================
This recipe is used to run one or more command lines.
I stole this from iw.recipe.cmd (http://pypi.python.org/pypi/iw.recipe.cmd/0.1)
It works differently tho, when it comes to executing shell commands. iw.recipe.cmd would push each command out separately in it's own shell. Here I push them out to a shell script, and then run the shell script. This way things like CD and other things that require state within the shell work great.
Also, I changed the way it works in the config file.
we have 2 options in the command.
[commandexample]
recipe = cp.recipe.cmd
install_cmds =
echo "install commands go here"
cd /tmp
echo `pwd`
echo 'see, I exist in one shell instance.'
update_cmds =
echo "update commands go here"
On install, install_cmds will be turned into a shell script, and then ran.
on update, update_cmds will be turned into a shell script and then ran. If you want update_cmds to be the same you can do something like this:
update_cmds = ${commandexample:install_cmd}
(where commandexample is the name of your part)
python code execution is unchanged in this version, and below are the original docs.
We need a config file::
>>> cfg = """
... [buildout]
... parts = cmds
...
... [cmds]
... recipe = iw.recipe.cmd
... on_install=true
... cmds= %s
... """
>>> test_file = join(sample_buildout, 'test.txt')
>>> cmds = 'touch %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)
Ok, so now we can touch a file for testing::
>>> print system(buildout)
Installing cmds.
>>> 'test.txt' in os.listdir(sample_buildout)
True
And remove it::
>>> test_file = join(sample_buildout, 'test.txt')
>>> cmds = 'rm -f %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)
>>> print system(buildout)
Uninstalling cmds.
Installing cmds.
>>> 'test.txt' in os.listdir(sample_buildout)
False
We can run more than one commands::
>>> cmds = '''
... touch %s
... rm -f %s
... ''' % (test_file, test_file)
>>> test_file = join(sample_buildout, 'test.txt')
>>> cmds = 'rm -f %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)
>>> print system(buildout)
Updating cmds.
>>> 'test.txt' in os.listdir(sample_buildout)
False
We can also run some python code::
>>> cfg = """
... [buildout]
... parts = py py2
...
... [py]
... recipe = iw.recipe.cmd:py
... on_install=true
... cmds=
... >>> sample_buildout = buildout.get('directory', '.')
... >>> print os.listdir(sample_buildout)
... >>> shutil.rmtree(os.path.join(sample_buildout, "bin"))
... >>> print os.listdir(sample_buildout)
... [py2]
... recipe = iw.recipe.cmd:py
... on_install=true
... cmds=
... >>> def myfunc(value):
... ... return value and True or False
... >>> v = 20
... >>> print myfunc(v)
... """
>>> write(sample_buildout, 'buildout.cfg', cfg)
Ok, so now we run it::
>>> print system(buildout)
Uninstalling cmds.
Installing py.
['.installed.cfg', 'bin', 'buildout.cfg', 'develop-eggs', 'eggs', 'parts']
['.installed.cfg', 'buildout.cfg', 'develop-eggs', 'eggs', 'parts']
Installing py2.
True
cp.recipe.cmd package
=====================
.. contents::
What is cp.recipe.cmd ?
=======================
This recipe is used to run one or more command lines.
I stole this from iw.recipe.cmd (http://pypi.python.org/pypi/iw.recipe.cmd/0.1)
It works differently tho, when it comes to executing shell commands. iw.recipe.cmd would push each command out separately in it's own shell. Here I push them out to a shell script, and then run the shell script. This way things like CD and other things that require state within the shell work great.
Also, I changed the way it works in the config file.
we have 2 options in the command.
[commandexample]
recipe = cp.recipe.cmd
install_cmds =
echo "install commands go here"
cd /tmp
echo `pwd`
echo 'see, I exist in one shell instance.'
update_cmds =
echo "update commands go here"
On install, install_cmds will be turned into a shell script, and then ran.
on update, update_cmds will be turned into a shell script and then ran. If you want update_cmds to be the same you can do something like this:
update_cmds = ${commandexample:install_cmd}
(where commandexample is the name of your part)
python code execution is unchanged in this version, and below are the original docs.
We need a config file::
>>> cfg = """
... [buildout]
... parts = cmds
...
... [cmds]
... recipe = iw.recipe.cmd
... on_install=true
... cmds= %s
... """
>>> test_file = join(sample_buildout, 'test.txt')
>>> cmds = 'touch %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)
Ok, so now we can touch a file for testing::
>>> print system(buildout)
Installing cmds.
>>> 'test.txt' in os.listdir(sample_buildout)
True
And remove it::
>>> test_file = join(sample_buildout, 'test.txt')
>>> cmds = 'rm -f %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)
>>> print system(buildout)
Uninstalling cmds.
Installing cmds.
>>> 'test.txt' in os.listdir(sample_buildout)
False
We can run more than one commands::
>>> cmds = '''
... touch %s
... rm -f %s
... ''' % (test_file, test_file)
>>> test_file = join(sample_buildout, 'test.txt')
>>> cmds = 'rm -f %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)
>>> print system(buildout)
Updating cmds.
>>> 'test.txt' in os.listdir(sample_buildout)
False
We can also run some python code::
>>> cfg = """
... [buildout]
... parts = py py2
...
... [py]
... recipe = iw.recipe.cmd:py
... on_install=true
... cmds=
... >>> sample_buildout = buildout.get('directory', '.')
... >>> print os.listdir(sample_buildout)
... >>> shutil.rmtree(os.path.join(sample_buildout, "bin"))
... >>> print os.listdir(sample_buildout)
... [py2]
... recipe = iw.recipe.cmd:py
... on_install=true
... cmds=
... >>> def myfunc(value):
... ... return value and True or False
... >>> v = 20
... >>> print myfunc(v)
... """
>>> write(sample_buildout, 'buildout.cfg', cfg)
Ok, so now we run it::
>>> print system(buildout)
Uninstalling cmds.
Installing py.
['.installed.cfg', 'bin', 'buildout.cfg', 'develop-eggs', 'eggs', 'parts']
['.installed.cfg', 'buildout.cfg', 'develop-eggs', 'eggs', 'parts']
Installing py2.
True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cp.recipe.cmd-0.2.tar.gz
(5.1 kB
view details)
Built Distribution
cp.recipe.cmd-0.2-py2.6.egg
(11.1 kB
view details)
File details
Details for the file cp.recipe.cmd-0.2.tar.gz
.
File metadata
- Download URL: cp.recipe.cmd-0.2.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cdad1ce1e75c9580b420a6a28fa4b7164ef95bbf7e70f0c0ad3e7d3dd4c94356 |
|
MD5 | 85ea4e871b804954dc9dc537ca2f4ff8 |
|
BLAKE2b-256 | c179870ea053beff7d5c54027bd0d9e98550ebf51dff50e6a85ecda469f84dd5 |
File details
Details for the file cp.recipe.cmd-0.2-py2.6.egg
.
File metadata
- Download URL: cp.recipe.cmd-0.2-py2.6.egg
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9721c21ff76ec2404b595bce449280320dc20628cfbfbfb02c4278acd1444078 |
|
MD5 | 883ab3b9dc089ff5aed3b932f02a838b |
|
BLAKE2b-256 | 87824ab059a6785bc19e5618e4fcd6a1f64d12d05ae22a227476de0c5c40c802 |