Coverage for src/pyenbc/remote/azure_transfer_api.py: 39%

23 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-20 05:47 +0200

1""" 

2@file 

3@brief API to move files 

4 

5.. versionadded:: 1.1 

6""" 

7try: 

8 from azure.common import AzureMissingResourceHttpError 

9except ImportError: 

10 AzureMissingResourceHttpError = Exception 

11from pyquickhelper.filehelper import TransferAPI 

12import pyquickhelper.loghelper as pyqlog 

13from .azure_drive import AzureDrive 

14 

15 

16class AzureTransferAPI(TransferAPI): 

17 """ 

18 defines an API to transfer files over a remote location 

19 

20 .. versionadded:: 1.1 

21 """ 

22 

23 def __init__(self, blob, key, fLOG=None, container="backup"): 

24 """ 

25 @param blob blob storage 

26 @param key key 

27 @param container container name 

28 @param fLOG logging function 

29 """ 

30 TransferAPI.__init__(self, fLOG) 

31 self.fLOG = fLOG if fLOG else pyqlog.noLOG 

32 self._azure = AzureDrive( 

33 blob, key, fLOG=self.fLOG, container=container) 

34 self._azure.connect() 

35 

36 def transfer(self, path, data): 

37 """ 

38 we assume a data holds in memory, 

39 tansfer data to path 

40 

41 @param data bytes 

42 @param path path to remove location 

43 @return boolean 

44 """ 

45 self._azure.upload_data(path, data) 

46 return True 

47 

48 def retrieve(self, path, exc=True): 

49 """ 

50 retrieve data from path 

51 

52 @param path remove location 

53 @param exc keep exception 

54 @return data 

55 """ 

56 if exc: 

57 return self._azure.download_data(path) 

58 else: 

59 try: 

60 return self._azure.download_data(path) 

61 except AzureMissingResourceHttpError: 

62 return None