跳转到主要内容

配置文件系统存储的食谱

项目描述

支持选项

该食谱支持以下选项

conf

配置文件的文件系统路径。需要文件的完整路径。

zope-instances

独立Zope实例或ZEO客户端实例的文件系统路径列表。每行一个路径。

storages

为您的buildout提供的FSS配置列表。第一行是全局配置。以下行是特定于Zope路径的配置。

每一行基于以下模型构建

name zope_path fss_strategy storage_filesystem_path backup_filesystem_path

前两个参数是必需的。其他参数需要按顺序提供:如果您需要定义storage_filesystem_path,则必须定义fss_strategy。它是一个基于空格的配置:参数中不要使用空格。

name

配置这部分的名字

zope_path

ZODB中的绝对路径

fss_strategy(可选)

目录(默认)、flat、site1和site2之间的策略

storage_filesystem_path(可选)

存储活动文件的文件系统路径。默认路径是$buildout_path/var/fss_storage_$name

backup_filesystem_path(可选)

存储文件备份的文件系统路径。默认路径是$buildout_path/var/fss_backup_$name

示例

[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调用,让我们创建一个实例,并模拟一个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 = 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 = 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>

现有数据

让我们将数据文件夹填充数据

>>> 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可能会将它们视为新文件。我们唯一应该得到的新文件是配置文件,因为它是唯一每次都重新写入的文件。

>>> 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 = 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-instances选项

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

项目详情


下载文件

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

源分布

iw.recipe.fss-0.2.1.tar.gz (8.0 kB 查看哈希值)

上传时间

构建分布

iw.recipe.fss-0.2.1-py2.4.egg (13.7 kB 查看哈希值)

上传时间

由...