跳转到主要内容

ZC Buildout 脚本以执行命令行

项目描述

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

变更历史

trunk (2008-04-22)

  • xxx [Ingeniweb]

0.3 (2008-04-22)

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

0.2 (2008-04-22)

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

  • win32 测试兼容 [gawel]

详细文档

支持选项

此脚本支持以下选项

on_install

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

on_update

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

cmds

一组命令行

shell

有效的解释器(仅限 POSIX)

示例用法

我们需要一个配置文件

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

贡献者

Gael Pasgrimaud

下载

项目详情


下载文件

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

源分发

iw.recipe.cmd-0.3.tar.gz (6.5 kB 查看哈希值)

上传时间

构建分发

iw.recipe.cmd-0.3-py2.4.egg (10.7 kB 查看哈希值)

上传时间

支持