quetzal.app.api.data.storage package

quetzal.app.api.data.storage.set_permissions(file_obj, owner)

Set the permissions of the file

Change the data object file_obj permissions to set owner as the user that owns this file.

Parameters
  • file_obj (object) – Object pointing to a file, as returned by upload().

  • owner (quetzal.app.models.User) – User object that will own the file.

Raises

quetzal.app.api.exceptions.QuetzalException – When the storage backend is unknown. Exceptions by the dispatched functions are not captured here.

quetzal.app.api.data.storage.upload(filename, contents, location)

Upload a file

Upload the contents as a file named filename in location.

This function dispaches the upload operation on the configured storage backend.

Parameters
  • filename (str) – Target file name where the contents will be saved.

  • contents (file-like) – A buffer of bytes with the file contents.

  • location (str) – URL of the target location where the file will be saved. This should be the URL of a workspace

Returns

  • url (str) – URL to where the file was uploaded.

  • obj (object) – An object pointing where the file was uploaded for further manipulation. Its type depends on the data backend.

Raises

quetzal.app.api.exceptions.QuetzalException – When the storage backend is unknown. Exceptions by the dispatched functions are not captured here.

Submodules

quetzal.app.api.data.storage.gcp module

quetzal.app.api.data.storage.gcp.set_permissions(blob, owner)
quetzal.app.api.data.storage.gcp.upload(filename, content, location)

Save a file on a local filesystem.

Implements the upload mechanism of the GCP backend.

Parameters
  • filename (str) – Filename where the file will be saved. It can include a relative path.

  • content (file-like) – Contents of the file.

  • location (str) – URL of the bucket the file will be saved. The filename parameter will be relative to this parameter.

Returns

  • url (str) – URL to the uploaded file. Its format will be gs://url/to/file.

  • blob_obj (google.cloud.storage.blob.Blob) – Blob object where the file was saved.

Raises

quetzal.app.api.exceptions.QuetzalException – When the location is the global data bucket. This is not permitted.

quetzal.app.api.data.storage.local module

quetzal.app.api.data.storage.local.set_permissions(file_obj, owner)
quetzal.app.api.data.storage.local.upload(filename, content, location)

Save a file on a local filesystem.

Implements the upload mechanism of the local file storage backend.

Parameters
  • filename (str) – Filename where the file will be saved. It can include a relative path.

  • content (file-like) – Contents of the file.

  • location (str) – URL where the file will be saved. The filename parameter will be relative to this parameter.

Returns

  • url (str) – URL to the uploaded file. Its format will be file://absolute/path/to/file.

  • path_obj (pathlib.Path) – Path object where the file was saved.

Raises

quetzal.app.api.exceptions.QuetzalException – When the location is the global data directory. This is not permitted.