#NEWLINE# def format_size( num_bytes ) : #NEWLINE# #INDENT# 'Pretty print a file size.' #NEWLINE# num_bytes = float ( num_bytes ) #NEWLINE# KiB = 1024 #NEWLINE# MiB = ( KiB * KiB ) #NEWLINE# GiB = ( KiB * MiB ) #NEWLINE# TiB = ( KiB * GiB ) #NEWLINE# PiB = ( KiB * TiB ) #NEWLINE# EiB = ( KiB * PiB ) #NEWLINE# ZiB = ( KiB * EiB ) #NEWLINE# YiB = ( KiB * ZiB ) #NEWLINE# if ( num_bytes > YiB ) : #NEWLINE# #INDENT# output = ( '%.3g YB' % ( num_bytes / YiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num_bytes > ZiB ) : #NEWLINE# #INDENT# output = ( '%.3g ZB' % ( num_bytes / ZiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num_bytes > EiB ) : #NEWLINE# #INDENT# output = ( '%.3g EB' % ( num_bytes / EiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num_bytes > PiB ) : #NEWLINE# #INDENT# output = ( '%.3g PB' % ( num_bytes / PiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num_bytes > TiB ) : #NEWLINE# #INDENT# output = ( '%.3g TB' % ( num_bytes / TiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num_bytes > GiB ) : #NEWLINE# #INDENT# output = ( '%.3g GB' % ( num_bytes / GiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num_bytes > MiB ) : #NEWLINE# #INDENT# output = ( '%.3g MB' % ( num_bytes / MiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( num_bytes > KiB ) : #NEWLINE# #INDENT# output = ( '%.3g KB' % ( num_bytes / KiB ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# output = ( '%.3g B' % num_bytes ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return output