配置文件系统存储的方法
iw.recipe.fss的Python项目详细描述
支持的选项
配方支持以下选项:
- 形态
- 配置文件的文件系统路径。需要完整的路径 文件。
- zope实例
- 独立zope实例或zeo客户端的文件系统路径列表 实例。一条线路。
- 存储
构建的FSS配置列表。 第一行是全局配置。以下是佐佩的台词 路径特定配置。
- 每条线都建立在以下模型上:
- 命名zope路径fss策略存储文件系统路径 备份文件系统路径
前两个参数是必需的。其他是按顺序需要的:如果 您需要定义存储文件系统路径您必须定义fss策略。 这是基于空间的配置:不要在参数中使用空格。
- 名称
- 这部分配置的名称
- Zope路径
- zodb中的绝对路径
- fss_策略(可选)
- 目录(默认)、平面、站点1和站点2之间的策略
- 存储文件系统路径(可选)
- 存储活动文件的文件系统路径。默认路径为 $buildout_path/var/fss_storage_u$name
- 备份文件系统路径(可选)
- 存储文件备份的文件系统路径。默认路径为 $buildout路径/var/fss\u备份名
示例:
[fss] recipe = iw.recipe.fss ## Deprecated #conf = ${zopeinstance:location}/etc/plone-filesystemstorage.conf # Replacement for 'conf' option zope-instances = ${zeoclient1:location} ${zeoclient2:location} storages = # The first is always generic global / # Others are always specific pone_flat /site flat /somewhere/files /somewhere/files_backup
示例用法
配方由buildout调用,让我们创建一个它的实例 构建模拟上下文:
>>> from zc.buildout.testing import * >>> import os; join = os.path.join >>> data_dir = join(test_dir, 'data') >>> data2_dir = join(test_dir, 'data2') >>> bin_dir = join(data_dir, 'bin') >>> var_dir = join(data_dir, 'var2') >>> conf_dir = join(data_dir, 'etc') >>> conf2_dir = join(data2_dir, 'etc') >>> buildout = {'zeoclient1': {'location': data_dir}, ... 'zeoclient2': {'location': data2_dir}, ... 'buildout': {'bin-directory': bin_dir}} >>> name = 'fss' >>> options = {'zope-instances': ''' ... %(zeoclient1_location)s ... %(zeoclient2_location)s ... ''' % {'zeoclient1_location': data_dir, 'zeoclient2_location': data2_dir}, ... 'storages': """ ... global / ... storage2 /site/storage2 flat ... storage3 /site/storage3 flat %(var)s/storage ... storage4 /site/storage4 flat %(var)s/sub/storage %(var)s/sub/backup ... """ % {'var': var_dir}}
创建配方:
>>> from iw.recipe.fss import Recipe >>> recipe = Recipe(buildout, name, options)
运行它:
>>> paths = list(recipe.install())
正在检查创建的文件。我们不希望这个配方列出创建的目录,所以 在卸载的情况下,它们不会被删除:
>>> paths.sort() >>> paths ['...data/etc/plone-filesystemstorage.conf', '...data2/etc/plone-filesystemstorage.conf']
检查conf文件:
>>> conf = open(join(conf_dir, ... 'plone-filesystemstorage.conf')) >>> print conf.read() # FSS conf file generated by iw.recipe.fss <BLANKLINE> # main storage global for / storage-path /.../data/var/fss_storage_global backup-path /.../data/var/fss_backup_global storage-strategy directory <BLANKLINE> # storage storage2 <site /site/storage2> storage-path /.../data/var/fss_storage_storage2 backup-path /.../data/var/fss_backup_storage2 storage-strategy flat </site> <BLANKLINE> # storage storage3 <site /site/storage3> storage-path /.../data/var2/storage backup-path /.../data/var/fss_backup_storage3 storage-strategy flat </site> <BLANKLINE> # storage storage4 <site /site/storage4> storage-path /.../sub/storage backup-path /.../sub/backup storage-strategy flat </site> <BLANKLINE> <BLANKLINE>
检查conf文件:
>>> conf = open(join(conf2_dir, ... 'plone-filesystemstorage.conf')) >>> print conf.read() # FSS conf file generated by iw.recipe.fss <BLANKLINE> # main storage global for / storage-path /.../data/var/fss_storage_global backup-path /.../data/var/fss_backup_global storage-strategy directory <BLANKLINE> # storage storage2 <site /site/storage2> storage-path /.../data/var/fss_storage_storage2 backup-path /.../data/var/fss_backup_storage2 storage-strategy flat </site> <BLANKLINE> # storage storage3 <site /site/storage3> storage-path /.../data/var2/storage backup-path /.../data/var/fss_backup_storage3 storage-strategy flat </site> <BLANKLINE> # storage storage4 <site /site/storage4> storage-path /.../sub/storage backup-path /.../sub/backup storage-strategy flat </site> <BLANKLINE> <BLANKLINE>
< H2>现有数据
让我们用数据填满数据文件夹:
>>> storage_dir = join(var_dir, 'storage') >>> data = 'xxxx' >>> f = open(join(storage_dir, 'data'), 'w') >>> f.write(data) >>> f.close() >>> ls(storage_dir) - data
让我们重新运行配方:
>>> paths = list(recipe.install())
让我们确保没有返回现有路径 配方,否则zc.buildout可能会将它们视为新文件。 我们应该得到的唯一新文件是conf文件,因为 它是唯一一个每次都被重写的:
>>> paths ['...plone-filesystemstorage.conf']
我们不应该泄露数据:
>>> ls(storage_dir) - data >>> for path in paths: ... try: ... os.rmdir(path) ... except: ... os.remove(path)
替代配置
尝试使用conf选项:
>>> buildout = {'instance': {'location': data_dir}, ... 'buildout': {'bin-directory': bin_dir}} >>> name = 'fss' >>> options = {'conf': join(conf_dir, ... 'plone-filesystemstorage.conf'), ... 'storages': """ ... global / ... storage2 /site/storage2 flat ... """ % {'var': var_dir}} >>> recipe = Recipe(buildout, name, options) >>> paths = list(recipe.install())
检查conf文件:
>>> conf = open(join(conf_dir, ... 'plone-filesystemstorage.conf')) >>> print conf.read() # FSS conf file generated by iw.recipe.fss <BLANKLINE> # main storage global for / storage-path /.../data/var/fss_storage_global backup-path /.../data/var/fss_backup_global storage-strategy directory <BLANKLINE> # storage storage2 <site /site/storage2> storage-path /.../data/var/fss_storage_storage2 backup-path /.../data/var/fss_backup_storage2 storage-strategy flat </site> <BLANKLINE>
尝试不使用conf或zope实例选项:
>>> buildout = {'instance': {'location': data_dir}, ... 'buildout': {'bin-directory': bin_dir}} >>> name = 'fss' >>> options = {'storages': """ ... global / ... storage2 /site/storage2 flat ... """ % {'var': var_dir}} >>> recipe = Recipe(buildout, name, options) >>> paths = list(recipe.install())
检查conf文件:
>>> conf = open(join(conf_dir, ... 'plone-filesystemstorage.conf')) >>> print conf.read() # FSS conf file generated by iw.recipe.fss <BLANKLINE> # main storage global for / storage-path /.../data/var/fss_storage_global backup-path /.../data/var/fss_backup_global storage-strategy directory <BLANKLINE> # storage storage2 <site /site/storage2> storage-path /.../data/var/fss_storage_storage2 backup-path /.../data/var/fss_backup_storage2 storage-strategy flat </site> <BLANKLINE>