storage — Camelot documentation

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot API »
- core »
- files »

# storage

class `camelot.core.files.storage.` `S3Storage`(upload_to='', stored_file_implementation=<class 'camelot.core.files.storage.StoredFile'>)

  Helper class that opens and saves StoredFile objects into Amazon S3.

  these attibutes need to be set in your settings for S3Storage to work :
    - AWS_ACCESS_KEY_ID = ‘<INSERT YOUR AWS ACCESS KEY ID HERE>’
    - AWS_SECRET_ACCESS_KEY = ‘<INSERT YOUR AWS SECRET ACCESS KEY HERE>’
    - AWS_BUCKET_NAME = ‘camelot’
    - AWS_LOCATION = S3.Location.DEFAULT

  Using this Storage requires the availability of S3.py on your PYTHONPATH. S3.py can be found on the amazon.com website

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

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

    Verify if the storage is available

    Returns: | True if the storage is available, False otherwise

  `checkin`(local_path, filename=None)

    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)

    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)

    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)

    Check the file stored_file out of the storage as a datastream

    Returns: | a file object

  `exists`(name)

    True if a file exists given some name

  `list`(prefix='*', suffix='*')

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

    Returns: | a iterator of StoredFile objects

  `path`(name)

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

  `writeable`()

    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)

  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`

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

class `camelot.core.files.storage.` `StoredImage`(storage, name)

  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)

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

    Returns: | a QImage

  `checkout_thumbnail`(*args, **kwargs)

    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

### Navigation

- index
- modules |
- next |
- previous |
- Camelot documentation »
- Camelot API »
- core »
- files »

Comments
blog comments powered by Disqus