#NEWLINE# def download( self , remote_path , local_path = None ) : #NEWLINE# #INDENT# self . log ( 'Building download request...' ) #NEWLINE# if ( local_path is None ) : #NEWLINE# #INDENT# local_path = '/var/panoptes/temp/{}' . format ( remote_path . rstrip ( '/' ) . split ( '/' ) [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# with open ( local_path , 'wb' ) as f : #NEWLINE# #INDENT# request = self . storage . objects ( ) . get_media ( bucket = self . project_id , object = remote_path ) #NEWLINE# media = MediaIoBaseDownload ( f , request , chunksize = self . CHUNKSIZE ) #NEWLINE# self . log ( 'Downloading bucket: {} object: {} to file: {}' . format ( self . project_id , remote_path , local_path ) ) #NEWLINE# progressless_iters = 0 #NEWLINE# done = False #NEWLINE# with console . ProgressBarOrSpinner ( 1.0 , 'Download status' ) as bar : #NEWLINE# #INDENT# while ( not done ) : #NEWLINE# #INDENT# error = None #NEWLINE# try : #NEWLINE# #INDENT# ( progress , done ) = media . next_chunk ( ) #NEWLINE# bar . update ( progress . progress ( ) ) #NEWLINE# #UNINDENT# except HttpError as err : #NEWLINE# #INDENT# error = err #NEWLINE# if ( err . resp . status < 500 ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# except self . RETRYABLE_ERRORS as err : #NEWLINE# #INDENT# error = err #NEWLINE# #UNINDENT# if error : #NEWLINE# #INDENT# progressless_iters += 1 #NEWLINE# self . handle_progressless_iter ( error , progressless_iters ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# progressless_iters = 0 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . log ( 'Download complete!' )