def _write_proxy(self, key, data, **kwargs): s3_obj = self.bucket.Object(key) bytesdata = io.BytesIO(data) s3_obj.upload_fileobj(bytesdata) bytesdata.close() res = StoreResult(success=True) return res
def _write_proxy(self, key, data, **kwargs): filepath = '{0}/{1}'.format(self.bucketdir.name, key) os.makedirs(os.path.dirname(filepath), exist_ok=True) fd = open(filepath, 'w+b') fd.write(data) fd.close() res = StoreResult(success=True) return res
def _read_proxy(self, key, update=False, **kwargs): s3_obj = self.bucket.Object(key) with tempfile.NamedTemporaryFile() as fd: s3_obj.download_fileobj(fd) fd.flush() fd.seek(0) data = fd.read() res = StoreResult(success=True, data=data) return res
def delete(self, key): """Remove key from store Args: key (String): the key to delete from store Returns: StoreResult: Operation Result """ try: res = self._delete_proxy(key) except Exception as e: traceback.print_exc() res = StoreResult(success=False, error=e) return res
def read(self, key, update=False, **kwargs): """Read data from Store Args: key (String): the key to read in the store Returns: StoreResult: Operation Result containing the data read from store """ try: res = self._read_proxy(key, update, **kwargs) except Exception as e: traceback.print_exc() res = StoreResult(success=False, error=e) return res
def write(self, key, data, **kwargs): """Write data to Store Args: key (String): the key to write in the store data (bytes): the data to write at key Returns: StoreResult: Operation Result """ wdata = data if isinstance(wdata, str): wdata = wdata.encode() try: res = self._write_proxy(key, wdata, **kwargs) except Exception as e: traceback.print_exc() res = StoreResult(success=False, error=e) return res
def _delete_proxy(self, key): self.bucket.Object(key).delete() res = StoreResult(success=True) return res
def _delete_proxy(self, key): filepath = '{0}/{1}'.format(self.bucketdir.name, key) os.remove(filepath) res = StoreResult(success=True) return res
def _read_proxy(self, key, update=False, **kwargs): fd = open('{0}/{1}'.format(self.bucketdir.name, key), 'rb') data = fd.read() fd.close() res = StoreResult(success=True, data=data) return res
def _delete_proxy(self, key): data = self.store_dict.pop(key, None) res = StoreResult(success=(data is not None)) return res
def _write_proxy(self, key, data, **kwargs): self.store_dict[key] = data res = StoreResult(success=True) return res
def _read_proxy(self, key, update=False, **kwargs): data = self.store_dict.get(key, None) res = StoreResult(success=(data is not None), data=data) return res