Skip to main content

Recipe to configure File System Storage

Project description

Supported options

The recipe supports the following options:

conf

Filesystem path for the configuration file. Need the complete path to the file.

zope-instances

List of filesystem paths for standalone zope instances or ZEO client instances. One path by line.

storages

List of FSS configurations for your buildout. The first line is for the global configuration. Following lines are by zope path specific configurations.

Each line is build on the below model:

name zope_path fss_strategy storage_filesystem_path backup_filesystem_path

The two first parameters are required. Others are needed sequentially: if you need to define storage_filesystem_path you have to define fss_strategy. It’s a space based configuration: don’t use spaces in parameters.

name

a name for these part of the configuration

zope_path

an absolute path in the ZODB

fss_strategy (optional)

a strategy between directory (default), flat, site1 and site2

storage_filesystem_path (optional)

filesystem path where active files are stored. Default path is $buildout_path/var/fss_storage_$name

backup_filesystem_path (optional)

filesystem path where files backup are stored. Default path is $buildout_path/var/fss_backup_$name

Example:

[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

Example usage

The recipe is called by buildout, let’s create an instance of it, with a buildout simulated context:

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

Creating the recipe:

>>> from iw.recipe.fss import Recipe
>>> recipe = Recipe(buildout, name, options)

Running it:

>>> paths = list(recipe.install())

Checking files created. We don’t want this recipe to list the created dir, so in case of uninstallation, they are never removed:

>>> paths.sort()
>>> paths
['...data/etc/plone-filesystemstorage.conf', '...data2/etc/plone-filesystemstorage.conf']

Checking the conf file:

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

Checking the conf file:

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

Existing data

Let’s fill the data folder with data:

>>> storage_dir = join(var_dir, 'storage')
>>> data = 'xxxx'
>>> f = open(join(storage_dir, 'data'), 'w')
>>> f.write(data)
>>> f.close()

>>> ls(storage_dir)
- data

Let’s re-run the recipe:

>>> paths = list(recipe.install())

Let’s make sure that no existing path was returned by the recipe, otherwise zc.buildout might treat them as new files. The only new file we should get is the conf file because it’s the only one that is re-written everytime:

>>> paths
['...plone-filesystemstorage.conf']

We shouldn’t loose the data:

>>> ls(storage_dir)
- data

>>> for path in paths:
...     try:
...         os.rmdir(path)
...     except:
...         os.remove(path)

Alternate configurations

Try with conf option:

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

Checking the conf file:

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

Try without conf nor zope-instances option:

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

Checking the conf file:

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iw.recipe.fss-0.2.0.tar.gz (7.9 kB view hashes)

Uploaded Source

Built Distribution

iw.recipe.fss-0.2.0-py2.4.egg (13.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page