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/fakestorage.py
Joseph Schorr 724b1607d7 Add automatic storage replication
Adds a worker to automatically replicate data between storages and update the database accordingly
2015-09-01 14:53:32 -04:00

35 lines
884 B
Python

from storage.basestorage import BaseStorage
from cStringIO import StringIO
_FAKE_STORAGE_MAP = {}
class FakeStorage(BaseStorage):
def _init_path(self, path=None, create=False):
return path
def get_content(self, path):
if not path in _FAKE_STORAGE_MAP:
raise IOError('Fake file %s not found' % path)
return _FAKE_STORAGE_MAP.get(path)
def put_content(self, path, content):
_FAKE_STORAGE_MAP[path] = content
def stream_read(self, path):
yield _FAKE_STORAGE_MAP[path]
def stream_read_file(self, path):
return StringIO(_FAKE_STORAGE_MAP[path])
def stream_write(self, path, fp, content_type=None, content_encoding=None):
_FAKE_STORAGE_MAP[path] = fp.read()
def remove(self, path):
_FAKE_STORAGE_MAP.pop(path, None)
def exists(self, path):
return path in _FAKE_STORAGE_MAP
def get_checksum(self, path):
return path