在控制台用户界面中执行命令的构建方法

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


Introduction

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

collective.recipe.cmd是一个Buildout配方,用于执行 控制台用户界面。

Usage

Supported options

配方支持以下选项:

on_install
如果命令必须在安装时运行,则为true
on_update
如果命令必须在更新时运行,则为true
cmds
一组命令行
uninstall_cmds
在构建卸载阶段执行的一组命令行
shell
有效的解释器(仅限POSIX)

Example usage

我们需要一个配置文件:

>>> 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脚本返回非零 退出/状态代码,然后引发异常并生成失败:

>>> 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

Contributors

  • Alter Way Solutions
  • 盖尔帕斯格里莫德
  • 洛伦佐·吉尔·桑切斯
  • 梅克·罗德
  • 乔西普德里奇

Changelog

0.11 (2015-06-06)

  • 添加对Python3.2和PyPy3的支持。
  • 增加对毒物测试的支持。
  • 修复与zope.testing4.2.0的兼容性。
  • 添加版本和实现trove分类器。

0.10 (2015-02-25)

  • 修复了pypy兼容性。[哈撒什]

0.9 (2014-10-04)

  • Python3。[工作]

0.8 (2013-11-05)

  • 修复包分发。[hvelarde]

0.7 (2013-11-04)

  • 如果从cmds生成的脚本返回非零,则失败 退出/状态代码。[帕特森]
  • 清除GPL残留物。[帕特森]

0.6 (2011-11-28)

  • 根据与Gawel[Jodok]商定的BSD重新授权

0.5 (2010-02-03)

  • 不运行命令,on-install/on-update设置为false。多亏了 肖恩·凯利的窃听报告 [槌]

0.4 (2009-08-18)

  • 添加对“uninstall\u cmds”选项的支持,以便在 卸载构建阶段。 [lgs,mroeder]

0.3 (2008-04-22)

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

0.2 (2008-04-22)

  • 在一个进程中运行命令 [槌]
  • win32测试兼容性 [槌]

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

推荐PyPI第三方库


热门话题
如何下载多个。java中的PDF文件   linux Java打开文件,形成实际用户主页~/   java如何在时间线内维护TableView选择?   java Hibernate注释@Where vs@WhereJoinTable   Java读/写访问异常FileNotFoundException(访问被拒绝)   继承在Java中是否可以扩展最后一个类?   Android HttpClient使用java使应用程序崩溃。lang.OutOfMemoryError:pthread_create   java为什么即使我在proguardproject中添加了jar文件,也会出现这种错误。txt?   如果添加JButton,swing Java FocusListener和KeyListener将无法工作   java使用solrj检索json格式的SolrDocument   使用Microsoft Visual Studio代码进行Java编程   java NoClassDefFoundError:org/apache/log4j/Logger   哈希集中包含相等对象的java   java中的参数化构造函数是否需要有一个主体?   java类似于NetBeans不必要的代码检测器   Java实践问题   java Blackberry“[projectname].调试文件丢失”和“I/O错误:找不到程序”jar