Skip to content

Commit

Permalink
Added create argument for gcs.GcsConnection.bucket() and s3.S3Connect…
Browse files Browse the repository at this point in the history
…ion.bucket().
  • Loading branch information
MartinMikita committed May 3, 2018
1 parent 2138488 commit a2aae6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cloudwrapper/gcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .base import BaseBucket

try:
from gcloud import storage
from gcloud import storage, exceptions
except ImportError:
from warnings import warn
install_modules = [
Expand All @@ -35,10 +35,15 @@ def __init__(self):
self.connection = storage.Client()


def bucket(self, name):
def bucket(self, name, create=False):
for _repeat in range(6):
try:
return Bucket(self.connection.get_bucket(name))
except (exceptions.NotFound) as e:
if create:
self.connection.create_bucket(name)
continue
raise
except (IOError, BadStatusLine) as e:
sleep(_repeat * 2 + 1)
if e.errno == errno.EPIPE:
Expand Down
13 changes: 10 additions & 3 deletions cloudwrapper/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

try:
from boto.s3 import connect_to_region, connection
from boto.exceptions import S3ResponseError
except ImportError:
from warnings import warn
install_modules = [
Expand Down Expand Up @@ -39,9 +40,15 @@ def __init__(self, region, key=None, secret=None, host=None):
aws_secret_access_key=secret)


def bucket(self, name):
return Bucket(self.connection.get_bucket(name))

def bucket(self, name, create=False):
for _ in range(6):
try:
return Bucket(self.connection.get_bucket(name))
except S3ResponseError as se:
if se.status == 404 and create:
self.connection.create_bucket(name)
continue
raise


class Bucket(object):
Expand Down

0 comments on commit a2aae6e

Please sign in to comment.