Add the basics of geographic data distribution and get the tests to work.
This commit is contained in:
parent
2bf12996f5
commit
bf98575feb
23 changed files with 198 additions and 100 deletions
|
@ -1,6 +1,7 @@
|
|||
from storage.local import LocalStorage
|
||||
from storage.s3 import S3Storage
|
||||
from storage.fakestorage import FakeStorage
|
||||
from storage.distributedstorage import DistributedStorage
|
||||
|
||||
|
||||
class Storage(object):
|
||||
|
@ -12,25 +13,32 @@ class Storage(object):
|
|||
self.state = None
|
||||
|
||||
def init_app(self, app):
|
||||
storage_type = app.config.get('STORAGE_TYPE', 'LocalStorage')
|
||||
path = app.config.get('STORAGE_PATH', '')
|
||||
# storage_type = app.config.get('STORAGE_TYPE', 'LocalStorage')
|
||||
# path = app.config.get('STORAGE_PATH', '')
|
||||
|
||||
if storage_type == 'LocalStorage':
|
||||
storage = LocalStorage(path)
|
||||
storages = {}
|
||||
for location, storage_params in app.config.get('DISTRIBUTED_STORAGE_CONFIG').items():
|
||||
driver = storage_params[0]
|
||||
|
||||
elif storage_type == 'S3Storage':
|
||||
access_key = app.config.get('STORAGE_AWS_ACCESS_KEY', '')
|
||||
secret_key = app.config.get('STORAGE_AWS_SECRET_KEY', '')
|
||||
bucket = app.config.get('STORAGE_S3_BUCKET', '')
|
||||
storage = S3Storage(path, access_key, secret_key, bucket)
|
||||
if driver == 'LocalStorage':
|
||||
storage = LocalStorage(*storage_params[1:])
|
||||
elif driver == 'S3Storage':
|
||||
storage = S3Storage(*storage_params[1:])
|
||||
else:
|
||||
storage = FakeStorage()
|
||||
|
||||
else:
|
||||
storage = FakeStorage()
|
||||
storages[location] = storage
|
||||
|
||||
preference = app.config.get('DISTRIBUTED_STORAGE_PREFERENCE', None)
|
||||
if not preference:
|
||||
preference = storages.keys()
|
||||
|
||||
d_storage = DistributedStorage(storages, preference)
|
||||
|
||||
# register extension with app
|
||||
app.extensions = getattr(app, 'extensions', {})
|
||||
app.extensions['storage'] = storage
|
||||
return storage
|
||||
app.extensions['storage'] = d_storage
|
||||
return d_storage
|
||||
|
||||
def __getattr__(self, name):
|
||||
return getattr(self.state, name, None)
|
||||
return getattr(self.state, name, None)
|
||||
|
|
Reference in a new issue