def __call__(self, bytes_amount): with self._lock: self._seen_so_far += bytes_amount if self._size > 0: percentage = (self._seen_so_far / self._size) * 100 sys.stdout.write( "\r%s %s / %s (%.2f%%)" % (self._label, human_readable_size(self._seen_so_far), human_readable_size(self._size), percentage)) sys.stdout.flush()
def __call__(self, bytes_amount): with self._lock: self._seen_so_far += bytes_amount if self._size > 0: percentage = (self._seen_so_far / self._size) * 100 sys.stdout.write( "\r%s %s / %s (%.2f%%)" % ( self._label, human_readable_size(self._seen_so_far), human_readable_size(self._size), percentage ) ) sys.stdout.flush()
def _make_size_str(self, size): """ This function creates the size string when objects are being listed. """ size_str = human_readable_size(size) if self._human_readable else str( size) return size_str.rjust(10, ' ')
def _print_progress(self, **kwargs): # Get all of the statistics in the correct form. remaining_files = self._get_expected_total( str(self._result_recorder.expected_files_transferred - self._result_recorder.files_transferred) ) # Create the display statement. if self._result_recorder.expected_bytes_transferred > 0: bytes_completed = human_readable_size( self._result_recorder.bytes_transferred + self._result_recorder.bytes_failed_to_transfer ) expected_bytes_completed = self._get_expected_total( human_readable_size( self._result_recorder.expected_bytes_transferred)) transfer_speed = human_readable_size( self._result_recorder.bytes_transfer_speed) + '/s' progress_statement = self.BYTE_PROGRESS_FORMAT.format( bytes_completed=bytes_completed, expected_bytes_completed=expected_bytes_completed, transfer_speed=transfer_speed, remaining_files=remaining_files ) else: # We're not expecting any bytes to be transferred, so we should # only print of information about number of files transferred. progress_statement = self.FILE_PROGRESS_FORMAT.format( files_completed=self._result_recorder.files_transferred, remaining_files=remaining_files ) if not self._result_recorder.expected_totals_are_final(): progress_statement += self._STILL_CALCULATING_TOTALS # Make sure that it overrides any previous progress bar. progress_statement = self._adjust_statement_padding( progress_statement, ending_char='\r') # We do not want to include the carriage return in this calculation # as progress length is used for determining whitespace padding. # So we subtract one off of the length. self._progress_length = len(progress_statement) - 1 # Print the progress out. self._print_to_out_file(progress_statement)
def _make_size_str(self, size): """ This function creates the size string when objects are being listed. """ if self._human_readable: size_str = human_readable_size(size) else: size_str = str(size) return size_str.rjust(10, ' ')
def _warn_if_too_large(self, fileinfo): if getattr(fileinfo, 'size') and fileinfo.size > MAX_UPLOAD_SIZE: file_path = relative_path(fileinfo.src) warning_message = ( "File %s exceeds s3 upload limit of %s." % ( file_path, human_readable_size(MAX_UPLOAD_SIZE))) warning = create_warning( file_path, warning_message, skip_file=False) self._result_queue.put(warning)
def _print_summary(self): """ This function prints a summary of total objects and total bytes """ print_str = str(self._total_objects) uni_print("\nTotal Objects: ".rjust(15, ' ') + print_str + "\n") print_str = human_readable_size( self._size_accumulator) if self._human_readable else str( self._size_accumulator) uni_print("Total Size: ".rjust(15, ' ') + print_str + "\n")
def _print_summary(self): """ This function prints a summary of total objects and total bytes """ print_str = str(self._total_objects) uni_print("\nTotal Objects: ".rjust(15, ' ') + print_str + "\n") if self._human_readable: print_str = human_readable_size(self._size_accumulator) else: print_str = str(self._size_accumulator) uni_print("Total Size: ".rjust(15, ' ') + print_str + "\n")
def _test_human_size_matches(bytes_int, expected): assert_equal(human_readable_size(bytes_int), expected)
def test_human_readable_size(bytes_int, expected): assert human_readable_size(bytes_int) == expected