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

collective.recipe.shelloutput的Python项目详细描述


此方法用于执行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]

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
regexjava:比较两个不包含参数的url的最简单方法   Java:使用干净的代码删除对象中不需要的字符   参数前缀“:”后不允许有java空间   java计算一个数组迭代的多个结果   无法创建java concat映像文件   JDK 6和JDK 7之间的java有效时间戳差异   java Gradle构建IO异常   浮点Java根据自定义术语将浮点转换为字节   eclipse Java卡片组   java编辑用户不断向数据库中添加新的   JavaWebLogic在生产中使用GC参数重新部署Performan   通过jsch com连接到服务器时发生java错误。jcraft。杰希。JSchException   在Java中快速读取巨大ascii文本文件的性能。需要使用MappedByteBuffer的帮助吗   java SFTP全局禁用主机验证   java将yslow与selenium测试集成   如何在Java9中按类获取模块名?   java为什么myBatis+postgresql 9.3即使查询成功也会发出回滚?   用于嵌套对象和数组的java JSON映射器   java两个单选按钮组,使用Thymeleaf,使用th:field,但覆盖名称   java将MathML转换为Ascimathml