=====================
iw.recipe.fss package
=====================

.. contents::

What is iw.recipe.fss ?
=======================

This recipe configure FSS Storage.


How to use iw.recipe.fss ?
==========================

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')
    >>> bin_dir = join(data_dir, 'bin')
    >>> var_dir = join(data_dir, 'var2')
    >>> conf_dir = join(data_dir, 'etc')
    >>> buildout = {'instance': {'location': data_dir},
    ...		    'buildout': {'bin-directory': bin_dir}}
    >>> name = 'fss'
    >>> options = {'conf': join(conf_dir,
    ...			                'plone-filesystemstorage.conf'),
    ...		   'storages': """
    ...			storage1 /site/storage1
    ...			storage2 /site/storage2 flat
    ...			storage3 /site/storage3 flat %(var)s/storage %(var)s/backup
    ...         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']

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 storage1 for /site/storage1
    storage-path /.../data/var/fss_storage_storage1
    backup-path /.../data/var/fss_backup_storage1
    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/var2/backup
     storage-strategy flat
    </site>
    <BLANKLINE>
    # storage storage4
    <site /site/storage4>
     storage-path /.../sub/storage
     backup-path /.../sub/backup
     storage-strategy flat
    </site>
    <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)



