Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1""" 

2@file 

3@brief API to move files 

4 

5.. versionadded:: 1.1 

6""" 

7import azure 

8from pyquickhelper.filehelper import TransferAPI 

9import pyquickhelper.loghelper as pyqlog 

10from .azure_drive import AzureDrive 

11 

12 

13class AzureTransferAPI(TransferAPI): 

14 """ 

15 defines an API to transfer files over a remote location 

16 

17 .. versionadded:: 1.1 

18 """ 

19 

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

21 """ 

22 @param blob blob storage 

23 @param key key 

24 @param container container name 

25 @param fLOG logging function 

26 """ 

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

28 self._azure = AzureDrive( 

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

30 self._azure.connect() 

31 

32 def transfer(self, path, data): 

33 """ 

34 we assume a data holds in memory, 

35 tansfer data to path 

36 

37 @param data bytes 

38 @param path path to remove location 

39 @return boolean 

40 """ 

41 self._azure.upload_data(path, data) 

42 return True 

43 

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

45 """ 

46 retrieve data from path 

47 

48 @param path remove location 

49 @param exc keep exception 

50 @return data 

51 """ 

52 if exc: 

53 return self._azure.download_data(path) 

54 else: 

55 try: 

56 return self._azure.download_data(path) 

57 except azure.common.AzureMissingResourceHttpError: 

58 return None