Storage base

The Storage class is designed to provide a standard interface for adding APIs that enable storage. This class defines the basic required functions that must be implimented for two classes inheriting this class to work in the same workflow, assuming the correct API keys are used. Switching storage objects should work seemlessly, if a Config object is used to initialize the Storage object. If the API credentials are folderectly provided, this cannot be guarantied because different services had different methods of initialization.

Different APIs might have different methods for identifying files. For example, Box uses IDs for files and folders, but another service might use a path from the root directory. The method of identifying files or folders is called a fid (file/folder identification) in DAPT. Different implimentations might use different protocols for files and folders, so the Storage methods should take care of this.

Required methods

There are four required methods that all Storage objects must implement. The required methods are download, delete, rename, and upload. These methods are based off REST APIs, although the underlying implimentation do not need to use REST.

class dapt.storage.base.Storage

Bases: object

connect()

The method used to connect to the database and log the user in. Some databases won’t need to use the connect method, but it should be called regardless to prevent problems.

Returns:True if the database connected successfully and False otherwise.
connected()

Check to see if the API is connected to the server and working.

Returns:True if the API is connected to the server and False otherwise.
delete_file(file_id)

Delete the the given file.

Parameters:file_id (str) – The file identification to be downloaded
Returns:True if successful and False otherwise
delete_folder(file_id)

Delete the given folder.

Parameters:file_id (str) – The folder identification to be downloaded
Returns:True if successful and False otherwise
download_file(file_id, folder='.', name=None, overwrite=True)

Download the file at the given file_id to the given path.

Parameters:
  • file_id (str) – The file identification to be downloaded
  • folder (str) – The directory where the file should be saved
  • name (str) – The name that the file should be saved as. If None is given (default), then the name of the file on the resource will be used.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if successful and False otherwise

download_folder(file_id, folder='.', name=None, overwrite=True)

Download the folder at the given file_id to the given path.

Parameters:
  • file_id (str) – The folder identification to be downloaded
  • folder (str) – The directory where the file should be saved
  • name (str) – The name that the file should be saved as. If None is given (default), then the name of the file on the resource will be used.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if successful and False otherwise

rename_file(file_id, name)

Rename the given file.

Parameters:
  • file_id (str) – The file identification to be downloaded
  • name (str) – The new name of the file or folder
Returns:

True if the file or folder was renamed, False otherwise.

rename_folder(file_id, name)

Rename the given folder.

Parameters:
  • file_id (str) – The folder identification to be downloaded
  • name (str) – The new name of the file or folder
Returns:

True if the file or folder was renamed, False otherwise.

upload_file(file_id, name, folder='.', overwrite=True)

Upload a file to the given folder.

Parameters:
  • file_id (str) – The folder where the file should be saved.
  • name (str) – The name that the file should be uploaded.
  • folder (str) – The directory where the file is stored.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if the upload was successful and False otherwise.

upload_folder(file_id, name, folder='.', overwrite=True)

Upload a folder to the given folder.

Parameters:
  • file_id (str) – The folder where the folder should be saved.
  • name (str) – The name that the file should be uploaded.
  • folder (str) – The directory where the file is stored.
  • overwrite (bool) – Should the data on your machine be overwritten. True by default.
Returns:

True if the upload was successful and False otherwise.

dapt.storage.base.check_overwrite_file(folder, name, overwrite, remove_existing)

This method checks to see if the file at the path specified should be overwritten.

Parameters:
  • folder (str) – The directory where the file might be.
  • name (str) – The name of the file
  • overwrite (bool) – Should the file be overwritten
  • remove_existing – (bool): Should the file be deleted if it already exists
Returns:

True if the file should be overwritten and False otherwise.

dapt.storage.base.check_overwrite_folder(folder, name, overwrite, make_folder)

This method checks to see if the file at the path specified should be overwritten.

Parameters:
  • folder (str) – The directory where the file might be.
  • name (str) – The name of the folder
  • overwrite (bool) – Should the file be overwritten
  • make_folder (bool) – Should the directory be made if it passes the overwrite test.
Returns:

True if the folder can be overwritten and was created (if make_folder was True) and False otherwise.

dapt.storage.base.get_mime_type(name)

Get the MIME type of the given file based on it’s file extension.

Parameters:name (str) – the name of the file including the extension
Returns:The MIME type of the file and None if the MIME type cannot be found.