Commits

Berry Phillips committed 26482bc

Load storage backend from config.

  • Participants
  • Parent commits 3d2e88f

Comments (0)

Files changed (2)

File s3_example_settings.yaml

 port: 8000
 ignore_favicon: True
 cloudfront_ugliness: True
-storage_backend: S3Storage
+storage: S3Storage
 s3_key: xxx
 s3_secret: xxx
 s3_bucket: xxx
 
 
 class S3Storage(object):
-    def __init__(self, key, secret, bucket):
+    def __init__(self, s3_key, s3_secret, s3_bucket, **kwargs):
         self.conn = connect_s3(key, secret)
         self.bucket = self.conn.get_bucket(bucket)
 
 
 
 class LocalStorage(object):
-    def __init__(self, root=None):
+    def __init__(self, root=None, **kwargs):
         self.root = os.path.realpath(root or os.path.dirname(__file__))
 
     def get_image(self, path):
 
 
 def app(environ,start_response):
-    # TODO: make this configurable.
-    sto = LocalStorage()
+    if config['storage'] == 'LocalStorage':
+        sto = LocalStorage(**config)
+    elif config['storage'] == 'S3Storage':
+        sto = S3Storage(**config)
+    else:
+        raise Exception('Invalid storage backend.')
 
     # throw away the leading slash on the path.
     path = environ['PATH_INFO']