跳转到主要内容

一个在控制台用户界面中执行命令的Buildout食谱

项目描述

简介

https://secure.travis-ci.org/collective/collective.recipe.cmd.png?branch=master

collective.recipe.cmd 是一个用于在控制台用户界面中执行命令的 Buildout 食谱。

用法

支持选项

该食谱支持以下选项

on_install

如果命令必须在安装时运行,则为true

on_update

如果命令必须在更新时运行,则为true

cmds

一组命令行

uninstall_cmds

一组在buildout卸载阶段执行的命令行

shell

一个有效的解释器(仅限POSIX)

示例用法

我们需要一个配置文件

>>> cfg = """
... [buildout]
... parts = cmds
...
... [cmds]
... recipe = collective.recipe.cmd
... on_install=true
... cmds= %s
... """

>>> test_file = join(sample_buildout, 'test.txt')
>>> cmds = 'echo "bouh" > %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)

好的,现在我们可以触摸一个文件进行测试

>>> print(system(buildout))
Installing cmds...

>>> 'test.txt' in os.listdir(sample_buildout)
True

并删除它

>>> test_file = join(sample_buildout, 'test.txt')
>>> if sys.platform == 'win32':
...    cmds = 'del %s' % test_file
... else:
...    cmds = 'rm -f %s' % test_file
>>> write(sample_buildout, 'buildout.cfg', cfg % cmds)

>>> print(system(buildout))
Uninstalling cmds.
Running uninstall recipe.
Installing cmds...

>>> 'test.txt' in os.listdir(sample_buildout)
False

我们可以运行多个命令

>>> if sys.platform == 'win32':
...     cmds = '''
... echo "bouh" > %s
... del %s
... ''' % (test_file, test_file)
... else:
...     cmds = '''
... echo "bouh" > %s
... rm -f %s
... ''' % (test_file, test_file)

>>> test_file = join(sample_buildout, 'test.txt')
>>> if sys.platform == 'win32':
...     cmds = 'del %s' % test_file
... else:
...     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

我们还可以运行一些Python代码

>>> cfg = """
... [buildout]
... parts = py py2
...
... [py]
... recipe = collective.recipe.cmd:py
... on_install=true
... cmds=
...   >>> sample_buildout = buildout.get('directory', '.')
...   >>> print(sorted(os.listdir(sample_buildout)))
...   >>> os.remove(os.path.join(sample_buildout, ".installed.cfg"))
...   >>> print(sorted(os.listdir(sample_buildout)))
... [py2]
... recipe = collective.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)

好的,现在我们来运行它

>>> print(system(buildout))
Uninstalling cmds.
Running uninstall recipe.
Installing py.
['.installed.cfg', 'bin', 'buildout.cfg', 'develop-eggs', 'eggs', 'parts']
['bin', 'buildout.cfg', 'develop-eggs', 'eggs', 'parts']
Installing py2.
True...

如果从命令生成的shell脚本返回一个非零退出/状态代码,则将引发异常,并且buildout将失败

>>> cfg = """
... [buildout]
... parts = cmds
...
... [cmds]
... recipe = collective.recipe.cmd
... on_install=true
... cmds= exit 23
... """

>>> write(sample_buildout, 'buildout.cfg', cfg)

>>> print(system(buildout))
Uninstalling py2.
Uninstalling py.
Installing cmds...
...CalledProcessError: Command 'sh .../run' returned non-zero exit status 23

贡献者

  • Alter Way Solutions

  • 盖尔·帕斯格里莫德

  • 洛伦佐·吉尔·桑切斯

  • 迈克·罗德

  • 约西普·德尔奇奇

变更日志

0.11 (2015-06-06)

  • 添加对Python 3.2和PyPy3的支持。

  • 添加对使用tox进行测试的支持。

  • 修复与zope.testing 4.2.0的兼容性。

  • 添加版本和实现分类器。

0.10 (2015-02-25)

  • 修复PyPy兼容性。[hathawsh]

0.9 (2014-10-04)

  • Python3。[jod]

0.8 (2013-11-05)

  • 修复包分发。[hvelarde]

0.7 (2013-11-04)

  • 如果从cmds生成的脚本返回非零退出/状态代码,则失败。[rpatterson]

  • 移除GPL残留。[rpatterson]

0.6 (2011-11-28)

  • 根据与gawel的协议重新许可为BSD。[jodok]

0.5 (2010-02-03)

  • 如果不运行命令,则设置on_install/on_update为false。感谢Sean Kelly提供的错误报告[gawel]

0.4 (2009-08-18)

  • 添加在卸载Buildout阶段执行命令的“uninstall_cmds”选项的支持。[lgs, mroeder]

0.3 (2008-04-22)

  • 应用最新的配方模板版本[gawel]

0.2 (2008-04-22)

  • 在一个进程中运行命令[gawel]

  • win32测试兼容[gawel]

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解更多关于安装包的信息。

源分发

由以下组织支持