From 98033f3270f882d817ecbe9fffb93d8ff79eb33b Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Tue, 22 Apr 2014 23:11:58 -0400 Subject: [PATCH] if the AWS S3 bucket does not exist, create it This makes the AWS S3 setup dead simple: just put in a awsbucket name of your choosing, set the AWS credentials, and it'll do the rest, whether the bucket exists already or not. S3 buckets are trivial to delete too, in case of error: `s3cmd rb s3://mybadbucketname`. --- fdroidserver/server.py | 8 ++++++-- setup.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/fdroidserver/server.py b/fdroidserver/server.py index c87df290..1e78cbfc 100644 --- a/fdroidserver/server.py +++ b/fdroidserver/server.py @@ -38,7 +38,7 @@ def update_awsbucket(repo_section): import libcloud.security libcloud.security.VERIFY_SSL_CERT = True - from libcloud.storage.types import Provider + from libcloud.storage.types import Provider, ContainerDoesNotExistError from libcloud.storage.providers import get_driver if 'awsaccesskeyid' not in config or 'awssecretkey' not in config: @@ -48,7 +48,11 @@ def update_awsbucket(repo_section): cls = get_driver(Provider.S3) driver = cls(config['awsaccesskeyid'], config['awssecretkey']) - container = driver.get_container(container_name=awsbucket) + try: + container = driver.get_container(container_name=awsbucket) + except ContainerDoesNotExistError: + container = driver.create_container(container_name=awsbucket) + logging.info('Created new container "' + container.name + '"') upload_dir = 'fdroid/' + repo_section if options.verbose: diff --git a/setup.py b/setup.py index 66e8de14..b4dd7e5e 100644 --- a/setup.py +++ b/setup.py @@ -32,7 +32,7 @@ setup(name='fdroidserver', 'paramiko', 'PIL', 'python-magic', - 'apache-libcloud >= 0.5', + 'apache-libcloud >= 0.14.1', ], classifiers=[ 'Development Status :: 3 - Alpha',