localclient

LocalClient(path)

Client interface for local file system.

auto_makedirs(destination)

Create directory tree if destination does not exist.

LocalClient

class cottoncandy.localclient.LocalClient(path)

Bases: cottoncandy.backend.CCBackEnd

Client interface for local file system.

Handle metadata in CouldStream objects by storing a json file (.meta.json).

__init__(path)
check_file_exists(cloud_name, bucket_name=None)

Checks whether a file exists on the cloud

Parameters
  • cloud_name (str) – file on cloud

  • bucket_name (str) – For a local client, the bucket is just a directory path. If None, use self.path.

Returns

Return type

bool

copy(source, destination, source_bucket, destination_bucket, overwrite)

Copies an object

Parameters
  • source (str) – origin path

  • destination (str) – destination path

  • source_bucket (ignored) –

  • destination_bucket (ignored) –

  • overwrite (bool) – overwrite if destination exists

Returns

Return type

bool, copy success

delete(cloud_name, recursive=False, delete=False)

Deletes an object

Parameters
  • cloud_name (str) – name of cloud object to delete

  • recursive (bool) – recursively delete directory?

  • delete (bool) – ignored

download_stream(cloud_name)

Downloads a object to an in-memory stream

Parameters

cloud_name (str) – name of object to download

Returns

Return type

CloudStream object

download_to_file(cloud_name, file_name)

Downloads an object directly to disk

Parameters
  • cloud_name (str) – name of object to download

  • file_name (str) – name on disk to use

Returns

Return type

bool, download success

get_object_metadata(object_name)

Get metadata associated with an object

get_object_size(object_name)

Get the size in bytes of an object

list_directory(path, limit)

Lists the content of a directory

Parameters
  • path (str) – path on the cloud to get contents for

  • limit (ignored) –

list_objects(**kwargs)

Gets all objects contained by backend

move(source, destination, source_bucket, destination_bucket, overwrite)

Moves an object

Parameters
  • source

  • destination

  • source_bucket

  • destination_bucket

  • overwrite

property size

Size of stored cloud items in bytes

Returns

Return type

int

upload_file(file_name, cloud_name, permissions)

Uploads a file from disk

Parameters
  • file_name (str) – name of file to upload

  • cloud_name (str) – name to use on the cloud

  • permissions (ignored) –

Returns

Return type

bool, upload success

upload_multipart(stream, cloud_name, metadata, permissions, buffersize, verbose)

Multi-part upload for large stream objects

Parameters
  • stream (stream) – streaming object

  • cloud_name (str) – name to use on cloud

  • metadata (dict) – custom metadata

  • permissions (str?) – permissions for this file

  • buffersize (int) – s3 uploading buffersize

  • verbose (bool) – s3 verbosity

Returns

Return type

bool, upload success

upload_stream(stream, cloud_name, metadata, permissions)

Uploads a stream object with a .read() function

Parameters
  • stream (stream) – streaming object, e.g. StringIO(json.dumps(my_dict)) (no metadata)

  • cloud_name (str) – name to use on cloud

  • metadata (dict) – custom metadata for this file

  • permissions (ignored) –

Returns

Return type

bool, upload success

auto_makedirs

cottoncandy.localclient.auto_makedirs(destination)

Create directory tree if destination does not exist.