chiark / gitweb /
if the AWS S3 bucket does not exist, create it
authorHans-Christoph Steiner <hans@eds.org>
Wed, 23 Apr 2014 03:11:58 +0000 (23:11 -0400)
committerHans-Christoph Steiner <hans@eds.org>
Wed, 23 Apr 2014 03:13:38 +0000 (23:13 -0400)
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
setup.py

index c87df290763d3f3e7fcc72f0edd47a18849c5608..1e78cbfc4a8870ff399d862bdcb8670ee5f8cb38 100644 (file)
@@ -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:
index 66e8de1455c3d831fd49ce97477fe56fe522d5f1..b4dd7e5e86cee5c4ab2e79104c933140a2b3ed28 100644 (file)
--- 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',