Source code for pyenbc.remote.azure_transfer_api

"""
API to move files

.. versionadded:: 1.1


:githublink:`%|py|7`
"""
import azure
from pyquickhelper.filehelper import TransferAPI
import pyquickhelper.loghelper as pyqlog
from .azure_drive import AzureDrive


[docs]class AzureTransferAPI(TransferAPI): """ defines an API to transfer files over a remote location .. versionadded:: 1.1 :githublink:`%|py|18` """
[docs] def __init__(self, blob, key, fLOG=None, container="backup"): """ :param blob: blob storage :param key: key :param container: container name :param fLOG: logging function :githublink:`%|py|26` """ self.fLOG = fLOG if fLOG else pyqlog.noLOG self._azure = AzureDrive( blob, key, fLOG=self.fLOG, container=container) self._azure.connect()
[docs] def transfer(self, path, data): """ we assume a data holds in memory, tansfer data to path :param data: bytes :param path: path to remove location :return: boolean :githublink:`%|py|40` """ self._azure.upload_data(path, data) return True
[docs] def retrieve(self, path, exc=True): """ retrieve data from path :param path: remove location :param exc: keep exception :return: data :githublink:`%|py|51` """ if exc: return self._azure.download_data(path) else: try: return self._azure.download_data(path) except azure.common.AzureMissingResourceHttpError: return None