#NEWLINE# def printTransferProgress( transferred , toBeTransferred , prefix = '' , postfix = '' , isBytes = True ) : #NEWLINE# #INDENT# 'Prints a progress bar\n\n    :param transferred: a number of items/bytes completed\n    :param toBeTransferred: total number of items/bytes when completed\n    :param prefix: String printed before progress bar\n    :param prefix: String printed after progress bar\n    :param isBytes: A boolean indicating whether to convert bytes to kB, MB, GB etc.\n\n    ' #NEWLINE# barLength = 20 #NEWLINE# status = '' #NEWLINE# if ( toBeTransferred < 0 ) : #NEWLINE# #INDENT# defaultToBeTransferred = ( ( barLength * 1 ) * MB ) #NEWLINE# if ( transferred > defaultToBeTransferred ) : #NEWLINE# #INDENT# progress = ( float ( ( transferred % defaultToBeTransferred ) ) / defaultToBeTransferred ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# progress = ( float ( transferred ) / defaultToBeTransferred ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( toBeTransferred == 0 ) : #NEWLINE# #INDENT# progress = 1 #NEWLINE# status = 'Done...\n' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# progress = ( float ( transferred ) / toBeTransferred ) #NEWLINE# if ( progress >= 1 ) : #NEWLINE# #INDENT# progress = 1 #NEWLINE# status = 'Done...\n' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# block = int ( round ( ( barLength * progress ) ) ) #NEWLINE# nbytes = ( humanizeBytes ( transferred ) if isBytes else transferred ) #NEWLINE# if ( toBeTransferred > 0 ) : #NEWLINE# #INDENT# outOf = ( '/%s' % ( humanizeBytes ( toBeTransferred ) if isBytes else toBeTransferred ) ) #NEWLINE# percentage = ( '%4.2f%%' % ( progress * 100 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# outOf = '' #NEWLINE# percentage = '' #NEWLINE# #UNINDENT# text = ( '\r%s [%s]%s     %s%s %s %s    ' % ( prefix , ( ( '#' * block ) + ( '-' * ( barLength - block ) ) ) , percentage , nbytes , outOf , postfix , status ) ) #NEWLINE# sys . stdout . write ( text ) #NEWLINE# sys . stdout . flush ( )