跳转到主要内容

执行shell命令并在构建过程中的另一部分重用输出。

项目描述

这个配方用于执行shell命令并在构建过程中的另一部分获取输出。命令定义在名为commands的节中,每行一个,输出可以使用${…}语法从其他部分引用。

>>> write('dummy.py',
... '''
... class Recipe(object):
...
...     def __init__(self, buildout, name, options):
...         self.options = options
...
...     def install(self):
...         if 'output_1' in self.options:
...             print self.options['output_1']
...         if 'output_2' in self.options:
...             print self.options['output_2']
...         return ()
...
...     def update(self):
...         pass
... ''')
>>> write('setup.py',
... '''
... from setuptools import setup
...
... setup(name='dummyrecipe',
...       entry_points = {'zc.buildout': ['default = dummy:Recipe']})
... ''')
>>> write('buildout.cfg',
... '''
... [buildout]
... develop = .
... parts =
...     shelloutput
...     use-shelloutput
... offline = true
...
... [shelloutput]
... recipe = collective.recipe.shelloutput
... commands =
...     echo_1 = echo 'ECHO'
...     echo_2 = echo 'The shell says: hello.'
...
... [use-shelloutput]
... recipe = dummyrecipe
... output_1 = ${shelloutput:echo_1}
... output_2 = ${shelloutput:echo_2}
... ''')
>>> print system(join('bin', 'buildout')),
Develop: '/sample-buildout/.'
Installing shelloutput.
Installing use-shelloutput.
ECHO
The shell says: hello.

如果我们给出一个空命令,我们将得到一个提示。

>>> write('buildout.cfg',
... '''
... [buildout]
... develop = .
... parts =
...     shelloutput
...     use-shelloutput
... offline = true
...
... [shelloutput]
... recipe = collective.recipe.shelloutput
... commands =
...     empty-cmd =
...
... [use-shelloutput]
... recipe = dummyrecipe
... output_1 = ${shelloutput:empty-cmd}
... ''')
>>> print system(join('bin', 'buildout')),
  Develop: '/sample-buildout/.'
  Uninstalling use-shelloutput.
  Uninstalling shelloutput.
  Installing shelloutput.
  Installing use-shelloutput.
  Empty command 'empty-cmd', no output generated.

如果命令的执行生成错误,我们将得到错误消息。

>>> write('buildout.cfg',
... '''
... [buildout]
... develop = .
... parts =
...     shelloutput
...     use-shelloutput
... offline = true
...
... [shelloutput]
... recipe = collective.recipe.shelloutput
... commands =
...     date = date -invalid-option
...
... [use-shelloutput]
... recipe = dummyrecipe
... output_1 = ${shelloutput:date}
... ''')
>>> print system(join('bin', 'buildout')),
Develop: '/sample-buildout/.'
Uninstalling use-shelloutput.
Uninstalling shelloutput.
Installing shelloutput.
Installing use-shelloutput.
Error 'date: invalid option ... for command 'date'...

变更历史

0.1 (2010-09-21)

  • 初始发布。 [j23d]

项目详情


下载文件

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

源代码发行版

collective.recipe.shelloutput-0.1.tar.gz (4.9 kB 查看哈希值)

上传时间 源代码

由以下支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面