<s> """<STR_LIT>""" <EOL> from gslib . util import MakeHumanReadable <EOL> from gslib . util import UTF8 <EOL> _START_BYTES_PER_CALLBACK = <NUM_LIT> * <NUM_LIT:64> <EOL> _MAX_BYTES_PER_CALLBACK = <NUM_LIT> * <NUM_LIT> * <NUM_LIT:100> <EOL> MAX_PROGRESS_INDICATOR_COLUMNS = <NUM_LIT> <EOL> class ProgressCallbackWithBackoff ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , total_size , callback_func , <EOL> start_bytes_per_callback = _START_BYTES_PER_CALLBACK , <EOL> max_bytes_per_callback = _MAX_BYTES_PER_CALLBACK , <EOL> calls_per_exponent = <NUM_LIT:10> ) : <EOL> """<STR_LIT>""" <EOL> self . _bytes_per_callback = start_bytes_per_callback <EOL> self . _callback_func = callback_func <EOL> self . _calls_per_exponent = calls_per_exponent <EOL> self . _max_bytes_per_callback = max_bytes_per_callback <EOL> self . _total_size = total_size <EOL> self . _bytes_processed_since_callback = <NUM_LIT:0> <EOL> self . _callbacks_made = <NUM_LIT:0> <EOL> self . _total_bytes_processed = <NUM_LIT:0> <EOL> def Progress ( self , bytes_processed ) : <EOL> """<STR_LIT>""" <EOL> self . _bytes_processed_since_callback += bytes_processed <EOL> if ( self . _bytes_processed_since_callback > self . _bytes_per_callback or <EOL> ( self . _total_bytes_processed + self . _bytes_processed_since_callback >= <EOL> self . _total_size and self . _total_size is not None ) ) : <EOL> self . _total_bytes_processed += self . _bytes_processed_since_callback <EOL> if self . _total_size is not None : <EOL> bytes_sent = min ( self . _total_bytes_processed , self . _total_size ) <EOL> else : <EOL> bytes_sent = self . _total_bytes_processed <EOL> self . _callback_func ( bytes_sent , self . _total_size ) <EOL> self . _bytes_processed_since_callback = <NUM_LIT:0> <EOL> self . _callbacks_made += <NUM_LIT:1> <EOL> if self . _callbacks_made > self . _calls_per_exponent : <EOL> self . _bytes_per_callback = min ( self . _bytes_per_callback * <NUM_LIT:2> , <EOL> self . _max_bytes_per_callback ) <EOL> self . _callbacks_made = <NUM_LIT:0> <EOL> def ConstructAnnounceText ( operation_name , url_string ) : <EOL> """<STR_LIT>""" <EOL> justified_op_string = operation_name [ : <NUM_LIT:11> ] . ljust ( <NUM_LIT:12> ) <EOL> start_len = len ( justified_op_string ) <EOL> end_len = len ( '<STR_LIT>' ) <EOL> if ( start_len + len ( url_string ) + end_len > <EOL> MAX_PROGRESS_INDICATOR_COLUMNS ) : <EOL> ellipsis_len = len ( '<STR_LIT>' ) <EOL> url_string = '<STR_LIT>' % url_string [ <EOL> - ( MAX_PROGRESS_INDICATOR_COLUMNS - start_len - end_len - ellipsis_len ) : ] <EOL> base_announce_text = '<STR_LIT>' % ( justified_op_string , url_string ) <EOL> format_str = '<STR_LIT>' % MAX_PROGRESS_INDICATOR_COLUMNS <EOL> return format_str . format ( base_announce_text . encode ( UTF8 ) ) <EOL> class FileProgressCallbackHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , announce_text , status_queue , start_byte = <NUM_LIT:0> , <EOL> override_total_size = None ) : <EOL> """<STR_LIT>""" <EOL> self . _announce_text = announce_text <EOL> self . _status_queue = status_queue <EOL> self . _start_byte = start_byte <EOL> self . _override_total_size = override_total_size <EOL> self . _last_byte_written = False <EOL> def call ( self , <EOL> last_byte_processed , <EOL> total_size ) : <EOL> """<STR_LIT>""" <EOL> if self . _last_byte_written : <EOL> return <EOL> if self . _override_total_size : <EOL> total_size = self . _override_total_size <EOL> if total_size : <EOL> total_size_string = '<STR_LIT>' % MakeHumanReadable ( total_size ) <EOL> else : <EOL> total_size_string = '<STR_LIT>' <EOL> self . _status_queue . put ( '<STR_LIT>' % ( <EOL> self . _announce_text , <EOL> MakeHumanReadable ( last_byte_processed - self . _start_byte ) , <EOL> total_size_string ) ) <EOL> if total_size and last_byte_processed - self . _start_byte == total_size : <EOL> self . _last_byte_written = True <EOL> self . _status_queue . put ( '<STR_LIT:\n>' ) </s>
