=======
Storage
=======

Helmholtz decouples storage of metadata and storage of data. The purpose of this
module is to store links or references that indicate where to find the actual
data, whether stored in files or in another database (although only files are
currently supported).

This component depends on :mod:`access_control`.

File servers
------------

Files may be stored on your local hard disk::

    >>> from helmholtz.storage.models import FileServer
    >>> my_laptop = FileServer(label="Bob's laptop")
    >>> my_laptop.save()
    
or on a networked machine::

    >>> from helmholtz.storage.models import CommunicationProtocol
    >>> smb = CommunicationProtocol.objects.filter(initials="SMB")
    >>> lab_file_server = FileServer(label="Smith Lab RAID array",
    ...                              protocol=smb, ip_address="192.168.0.22",
    ...                              port=139)
    >>> lab_file_server.save()
    

File paths
----------

To make it easier to move data around without having to change potentially
thousands of entries, we store the filesystem path of the directory/folder
containing the datafile separately, e.g.::

    >>> from helmholtz.storage.models import FileLocation
    >>> folder = FileLocation(server=my_laptop, root="C:\data", path="2010\jan\24")
    >>> folder.save()
    
Now if we move all the data to a new disk, we can just change the root::

    >>> folder.root = "H:\"
    
    >>> folder.save()


Data files
----------

    >>> from helmholtz.storage.models import File, MimeType
    >>> csv = MimeType.objects.get(extension="csv")
    >>> data_file = File(name="20100124_A.csv", location=folder, mimetype="csv")
    >>> data_file.save()


Reference
---------

.. automodule:: helmholtz.storage.models

.. autoclass:: CommunicationProtocol
   :members:
   
.. autoclass:: MimeType
   :members:

.. autoclass:: FileServer
   :members:

.. autoclass:: FileLocation
   :members:

.. autoclass:: File
   :members:
