gstorage.bucket¶
A thin wrapper around gcloud.bucket with convenience methods to interact with buckets
>>> from gstorage.bucket import Bucket
>>> bucket = Bucket.get_default()
>>> bucket.copydir('/share/images')
-
class
gstorage.bucket.
Bucket
(client, name=None)¶ -
copydir
(path)¶ Copy the contents of the local directory given by path to google cloud. Maintain the same directory structure on remote. This is (intentionally) a blocking call, so clients can report errors if the transfer fails.
Parameters: path (string) – relative or absolute path to the directory that needs to be copied
Returns: True when transfer is complete
Raises: - OSError – path doesn’t exist or permission denied
- ValueError – if the library cannot determine the file size
- gcloud.exceptions.GCloudError – if upload status gives error response
-
classmethod
get_default
()¶ Get an instance of the default bucket identified fy GCLOUD_DEFAULT_BUCKET_NAME
Parameters: cls –
gstorage.bucket.Bucket
Returns: Bucket
objectRaises: - gcloud.exceptions.BadRequest (400) – not a valid bucket name
- gcloud.exceptions.Forbidden (403) – The credentials are invalid
-
classmethod
get_or_create
(bucket_name, client=None)¶ If the bucket exists with this name, get it. Else, create it
Parameters: - cls –
gstorage.bucket.Bucket
- bucket_name (string) – name of the bucket
- client (gcloud.client.Client) – (optional) instance of client to use
Returns: Bucket
objectRaises: - gcloud.exceptions.BadRequest (400) – not a valid bucket name
- gcloud.exceptions.Forbidden (403) – The credentials are invalid
- cls –
-