localclient¶
|
Client interface for local file system. |
|
Create directory tree if destination does not exist. |
LocalClient¶
- class cottoncandy.localclient.LocalClient(path: str)¶
Bases:
CCBackEndClient interface for local file system.
Handle metadata in CouldStream objects by storing a json file (.meta.json).
- __init__(path: str)¶
- 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.
- Return type:
bool
- copy(source, destination, source_bucket, destination_bucket, overwrite, copy_metadata=True)¶
Copies an object
- Parameters:
source (str) – origin path
destination (str) – destination path
source_bucket (ignored)
destination_bucket (ignored)
overwrite (bool) – overwrite if destination exists
copy_metadata (bool) – also copy metadata file? (we don’t want to do this if copying from the local filesystem)
- Return type:
bool, copy success
- delete(cloud_name, recursive=FAKE_SECRET_KEY, delete=FAKE_SECRET_KEY)¶
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, threads=1)¶
Downloads a object to an in-memory stream
- Parameters:
cloud_name (str) – name of object to download
- Return type:
CloudStream object
- download_to_file(cloud_name, file_name, threads=1)¶
Downloads an object directly to disk
- Parameters:
cloud_name (str) – name of object to download
file_name (str) – name on disk to use
- 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
- Return type:
int
- upload_file(file_name, cloud_name, permissions, threads=1)¶
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)
- Return type:
bool, upload success
- upload_stream(stream, cloud_name, metadata, permissions, threads=1)¶
Uploads a stream object with a .read() function
- Parameters:
threads
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)
- Return type:
bool, upload success
auto_makedirs¶
- cottoncandy.localclient.auto_makedirs(destination: str) None¶
Create directory tree if destination does not exist.