#NEWLINE# def write_file( self , file_object , filename ) : #NEWLINE# #INDENT# ' Write the specified file. ' #NEWLINE# file_object . seek ( 0 , os . SEEK_END ) #NEWLINE# file_size = file_object . tell ( ) #NEWLINE# file_object . seek ( 0 ) #NEWLINE# file_path = os . path . join ( self . DROPBOX_DIRECTORY , filename ) #NEWLINE# file_number = 0 #NEWLINE# while ( file_object . tell ( ) < file_size ) : #NEWLINE# #INDENT# upload_id = None #NEWLINE# chunk = None #NEWLINE# numbered_file_offset = 0 #NEWLINE# numbered_file_size = min ( self . DBBACKUP_DROPBOX_FILE_SIZE_LIMIT , ( file_size - file_object . tell ( ) ) ) #NEWLINE# while ( numbered_file_offset < numbered_file_size ) : #NEWLINE# #INDENT# chunk_size = min ( CHUNK_SIZE , ( numbered_file_size - numbered_file_offset ) ) #NEWLINE# if ( chunk is None ) : #NEWLINE# #INDENT# chunk = file_object . read ( chunk_size ) #NEWLINE# #UNINDENT# for try_number in range ( ( RETRY_COUNT + 1 ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( numbered_file_offset , upload_id ) = self . dropbox . upload_chunk ( chunk , chunk_size , numbered_file_offset , upload_id ) #NEWLINE# chunk = None #NEWLINE# #UNINDENT# except dropbox . rest . ErrorResponse : #NEWLINE# #INDENT# print ( '    Chunk upload failed' ) #NEWLINE# if ( try_number == RETRY_COUNT ) : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# print ( '    Retry' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# upload_progress = ( ( file_object . tell ( ) / file_size ) * 100 ) #NEWLINE# print ( '    Uploaded {:4.1f}%' . format ( upload_progress ) ) #NEWLINE# #UNINDENT# numbered_file_path = self . get_numbered_path ( file_path , file_number ) #NEWLINE# numbered_file_full_path = os . path . join ( self . dropbox . session . root , numbered_file_path ) #NEWLINE# print ( '    Commit to {}' . format ( numbered_file_path ) ) #NEWLINE# self . dropbox . commit_chunked_upload ( numbered_file_full_path , upload_id ) #NEWLINE# file_number += 1