def delete_file_on_drive(service, eeout_file_id): failure_counter = 0 while failure_counter < 5: try: service.files().delete(fileId=eeout_file_id).execute() break except: gen.exponential_backoff(failure_counter) failure_counter = failure_counter + 1 if(failure_counter == 5): print "Failed deletion"
def download_file(service, eeout_file_id): request = service.files().get_media(fileId=eeout_file_id) fh = io.BytesIO() downloader = gac.http.MediaIoBaseDownload(fh, request) failure_counter = 0 while failure_counter < 5: try: status, done = downloader.next_chunk() print "\t Downloading Output %d%%." % int(status.progress() * 100) break except: gen.exponential_backoff(failure_counter) failure_counter = failure_counter+1 if(failure_counter == 5): fh=None print "Failed download" return fh