zc buildout recipe执行命令行

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


警告:此包已弃用。您应该使用collective.recipe.cmd

Change history

trunk (2008-04-22)

  • xxx [Ingeniweb]

0.3 (2008-04-22)

  • apply last version of the recipe template [gawel]

0.2 (2008-04-22)

  • run commands in one process [gawel]
  • win32 tests compat [gawel]

Detailed Documentation

Supported options

配方支持以下选项:

安装时

true if the commands must run on install

更新时

true if the commands must run on update

指挥管理系统

a set of command lines

外壳

a valid interpreter (POSIX only)

Example usage

我们需要一个配置文件:

>>> cfg = """
... [buildout]
... parts = cmds
...
... [cmds]
... recipe = iw.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.
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 = iw.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 = 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)

好的,现在我们运行它:

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

Contributors

盖尔帕斯格里莫德

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

推荐PyPI第三方库


热门话题
Gson类中的java验证错误   If和elseif之间的java差异?   字典Java8地图。输入比较器   java连接到远程计算机以获得WMI支持   java如何使用改型处理JSON对象中的空值   在Java中使用Comparator时不可编译的源代码   java将Jar添加到JSP的运行时路径   带有随机对象的while循环的java大O时间复杂性   java可以在不考虑参数的情况下模拟方法吗?   java我有一个简单的代码,它不工作。无法修复错误“println”   向eclipse添加Xively java库   java是否可以启用本机代码的缓存?   全局变量如何在Java中的所有类之间共享要使用的语言环境?   Java内存游戏如何翻转单个卡?