Package amplee :: Package storage :: Module storetar :: Class TarFileStorage
[hide private]
[frames] | no frames]

Class TarFileStorage

source code

object --+    
         |    
   Storage --+
             |
            TarFileStorage

Instance Methods [hide private]
 
__init__(self, storage_path, compression='gz', encoding='utf-8')
Simple tar archive storage for amplee.
source code
 
shutdown(self)
Does nothing effectively.
source code
object
create_container(self, collection_name)
Creates a subdirectory within the storage directory If it already exists does nothing.
source code
StorageResourceInfo or subclass
info(self, collection_name, resource_name=None, archive_sub_path=None)
Returns a StorageResourceInfo which ``key`` attribute is a TarFileStoragePathInfo.
source code
 
__get_file_mode(self, opening_mode='r')
Returns teh correct file mode to open an archive.
source code
 
__get_archive_name(self, resource_name)
Returns the name of the archive with the correct extension depending on the compression set on the storage.
source code
object
get_content(self, info)
Returns a list of tuples (StorageResourceInfo instance, content) based on provided path.
source code
string
get_meta_data(self, info)
Returns a byte string of the atom entry representing the member resource.
source code
 
put_content(self, info, content, **kwargs)
Replaces the tar achive at ``info.key`` with a new set of content.
source code
 
put_meta_data(self, info, content, **kwargs)
Replaces the tar achive at ``info.key`` with a new set of content.
source code
 
remove_content(self, info)
Remove the resource at 'info.key'
source code
 
remove_meta_data(self, info)
Remove the resource at 'info.key'
source code
 
persist(self, *args, **kwargs)
Does nothing in the filesystem storage
source code
bool
exists(self, info)
Returns True if the resource at 'info' exists.
source code
dict
ls(self, collection_name, ext=None)
List resources with the provided extension in a collection
source code
tuple
ils(self, collection_name, ext=None)
Yields resources with the provided extension in a collection
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, storage_path, compression='gz', encoding='utf-8')
(Constructor)

source code 

Simple tar archive storage for amplee.

If storage path does not exist, it is created.

Keyword arguments: storage_path -- absolute path to the top level directory which will contain collections and resources

compression -- should be either None for no compression, gz for a gzip compression or bz2 for a bzip2 compression scheme.

encoding -- used to encode the path elements
Overrides: object.__init__

shutdown(self)

source code 
Does nothing effectively.
Overrides: Storage.shutdown

create_container(self, collection_name)

source code 

Creates a subdirectory within the storage directory If it already exists does nothing.

Keyword argument collection_name -- name of the directory to create
Returns: object
the subclass may or may not return an object upon the creation of the container
Overrides: Storage.create_container

info(self, collection_name, resource_name=None, archive_sub_path=None)

source code 
Returns a StorageResourceInfo which ``key`` attribute is a TarFileStoragePathInfo.
Returns: StorageResourceInfo or subclass
an object representing the resource within the storage
Overrides: Storage.info

__get_file_mode(self, opening_mode='r')

source code 

Returns teh correct file mode to open an archive.

Keyword arguments: opening_mode -- how to open the archive, either in read mode 'r' or in write mode 'w'

__get_archive_name(self, resource_name)

source code 

Returns the name of the archive with the correct extension depending on the compression set on the storage.

Removes any extension in resource_name.

Keyword arguments: resoure_name -- any resource name value

get_content(self, info)

source code 

Returns a list of tuples (StorageResourceInfo instance, content) based on provided path.

If the info.key.archive_sub_path is None, then the returned list contains all the members of the archive and therefore its entire content.

Otherwise it returns only one single tuple matching the info.key.archive_sub_path value.

Note also that the data read from the archive is not decoded and is therefore returned as a byte string.

Keyword arguments info -- as returned by info()
Returns: object
content of the resource
Overrides: Storage.get_content

get_meta_data(self, info)

source code 

Returns a byte string of the atom entry representing the member resource.

Note also that the data read from the archive is not decoded and is therefore returned as a byte string.

Keyword arguments info -- as returned by info()
Returns: string
content of the atom entry
Overrides: Storage.get_meta_data

put_content(self, info, content, **kwargs)

source code 

Replaces the tar achive at ``info.key`` with a new set of content.

The ``content`` parameter is a list of tuples of the following form: (member_name_of_the_archive, data, data_length).

The first part of the tuple is the name used as the member of the archive

The second part is the data to be persisted. Thus must be a byte string, unicode string or a fileobject which MUST return the full content as a byte string on read()

The last part is the size to read from data and to persist into the archive.

Note that if the data is unicode, it will be encoded using UTF-8.

Keyword arguments info -- as returned by info() content -- list of tuples of the data to persist
Overrides: Storage.put_content

put_meta_data(self, info, content, **kwargs)

source code 

Replaces the tar achive at ``info.key`` with a new set of content.

Keyword arguments info -- as returned by info()

content -- byte string, unicode string or a file object which returns the full data as a byte string on read() and return the correct length on __len__
Overrides: Storage.put_meta_data

remove_content(self, info)

source code 

Remove the resource at 'info.key'

Keyword arguments info -- as returned by info()
Overrides: Storage.remove_content

remove_meta_data(self, info)

source code 

Remove the resource at 'info.key'

Keyword arguments info -- as returned by info()
Overrides: Storage.remove_meta_data

persist(self, *args, **kwargs)

source code 
Does nothing in the filesystem storage
Overrides: Storage.persist

exists(self, info)

source code 

Returns True if the resource at 'info' exists. False otherwise.

If info.key.archive_sub_path is set it will lookup in the archive if it exists.

Keyword arguments info -- as returned by info()
Returns: bool
True if the test succeeds, False otherwise.
Overrides: Storage.exists

ls(self, collection_name, ext=None)

source code 

List resources with the provided extension in a collection

Note that this will open each archive within the collection that matches the compression set for the storage: * 'gz' will result in searching through '*.tar.gz' * 'bz2' will result in searching through '*.tar.bz2' * None will result in searching through '*.tar'

The speed of this method will therefore decrease with the number of archives stored.

Keyword arguments collection_name -- name of the directory in the working copy containing all the members of a collection. Created if it does not exists.

ext -- extension of resources to return
Returns: dict
a dictionnary of existing members, their identifier and a StorageResourceInfo instance representing the resource.
Overrides: Storage.ls

ils(self, collection_name, ext=None)

source code 

Yields resources with the provided extension in a collection

Note that this will open each archive within the collection that matches the compression set for the storage: * 'gz' will result in searching through '*.tar.gz' * 'bz2' will result in searching through '*.tar.bz2' * None will result in searching through '*.tar'

The speed of this method will therefore decrease with the number of archives stored.

Keyword arguments collection_name -- name of the directory in the working copy containing all the members of a collection. Created if it does not exists.

ext -- extension of resources to return
Returns: tuple
existing members, their identifier and a StorageResourceInfo instance representing the resource.
Overrides: Storage.ils