storage

class camelot.core.files.storage.Storage(upload_to='', stored_file_implementation=<class 'camelot.core.files.storage.StoredFile'>, root=None)[source]

Helper class that opens and saves StoredFile objects The default implementation stores files in the settings.CAMELOT_MEDIA_ROOT directory. The storage object should only be used within the model thread, as all of it’s methods might block.

The methods of this class don’t verify if they are called on the model thread, because these classes can be used server side or in a non-gui script as well.

available()[source]

Verify if the storage is available

Returns:True if the storage is available, False otherwise
checkin(local_path, filename=None)[source]

Check the file pointed to by local_path into the storage, and return a StoredFile

Parameters:
  • local_path – the path to the local file that needs to be checked in
  • filename – a hint for the filename to be given to the checked in file, if None

is given, the filename from the local path will be taken.

The stored file is not guaranteed to have the filename asked, since the storage might not support this filename, or another file might be named like that. In each case the storage will choose the filename.

checkin_stream(prefix, suffix, stream)[source]

Check the datastream in as a file into the storage

Parameters:
  • prefix – the prefix to use for generating a file name
  • suffix – the suffix to use for generating a filen name, eg ‘.png’
Returns:

a StoredFile

This method can also be used in combination with the StringIO module:

import StringIO
    
stream = StringIO.StringIO()
# write everything to the stream
stream.write( 'bla bla bla' )
# prepare the stream for reading
stream.seek( 0 )
stored_file = storage.checkin_stream( 'document', '.txt', stream )
checkout(stored_file)[source]

Check the file pointed to by the local_path out of the storage and return a local filesystem path where the file can be opened

checkout_stream(stored_file)[source]

Check the file stored_file out of the storage as a datastream

Returns:a file object
exists(name)[source]

True if a file exists given some name

list(prefix='*', suffix='*')[source]

Lists all files with a given prefix and or suffix available in this storage

Returns:a iterator of StoredFile objects
path(name)[source]

The local filesystem path where the file can be opened using Python standard open

writeable()[source]

Verify if the storage is available and writeable

Returns:True if the storage is writeable, False otherwise
class camelot.core.files.storage.StoredFile(storage, name)[source]

Helper class for the File field type. Stored file objects can be used within the GUI thread, as none of its methods should block.

verbose_name[source]

The name of the file, as it is to be displayed in the GUI

class camelot.core.files.storage.StoredImage(storage, name)[source]

Helper class for the Image field type Class linking an image and the location and filename where the image is stored

checkout_image(*args, **kwargs)[source]

Checkout the image from the storage, this function is only to be used in the model thread.

Returns:a QImage
checkout_thumbnail(*args, **kwargs)[source]

Checkout a thumbnail for this image from the storage, this function is only to be used in the model thread :param width: the requested width of the thumbnail

Returns:a QImage

Previous topic

files

Next topic

license

This Page