This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/storage/__init__.py

44 lines
1.3 KiB
Python

from storage.local import LocalStorage
from storage.s3 import S3Storage
from storage.fakestorage import FakeStorage
from storage.distributedstorage import DistributedStorage
class Storage(object):
def __init__(self, app=None):
self.app = app
if app is not None:
self.state = self.init_app(app)
else:
self.state = None
def init_app(self, app):
# storage_type = app.config.get('STORAGE_TYPE', 'LocalStorage')
# path = app.config.get('STORAGE_PATH', '')
storages = {}
for location, storage_params in app.config.get('DISTRIBUTED_STORAGE_CONFIG').items():
driver = storage_params[0]
if driver == 'LocalStorage':
storage = LocalStorage(*storage_params[1:])
elif driver == 'S3Storage':
storage = S3Storage(*storage_params[1:])
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'] = d_storage
return d_storage
def __getattr__(self, name):
return getattr(self.state, name, None)