pypicloud.storage.base module

Base class for storage backends

class pypicloud.storage.base.IStorage(request: Request, **kwargs)[source]

Bases: object

Base class for a backend that stores package files

check_health() Tuple[bool, str][source]

Check the health of the storage backend

Returns
(healthy, status)(bool, str)

Tuple that describes the health status and provides an optional status message

classmethod configure(settings)[source]

Configure the storage method with app settings

delete(package: Package) None[source]

Delete a package file

Parameters
packagePackage

The package metadata

download_response(package: Package)[source]

Return a HTTP Response that will download this package

This is called from the download endpoint

get_url(package: Package) str[source]

Create or return an HTTP url for a package file

By default this will return a link to the download endpoint

/api/package/<package>/<filename>

Returns
linkstr

Link to the location of this package file

list(factory: ~typing.Type[~pypicloud.models.Package] = <class 'pypicloud.models.Package'>) List[Package][source]

Return a list or generator of all packages

open(package: Package)[source]

Get a buffer object that can read the package data

This should be a context manager. It is used in migration scripts, not directly by the web application.

Parameters
packagePackage

Examples

with storage.open(package) as pkg_data:
    with open('outfile.tar.gz', 'w') as ofile:
        ofile.write(pkg_data.read())
upload(package: Package, datastream: BinaryIO) None[source]

Upload a package file to the storage backend

Parameters
packagePackage

The package metadata

datastreamfile

A file-like object that contains the package data