
    Q                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r
  S	rS
rSrSr " S S\5      r " S S\5      rg)z(Helper functions for progress callbacks.    )absolute_import)print_function)division)unicode_literalsN)ProgressMessage)parallelism_framework_utili   i  @   A   c                   ,    \ rS rSrSr\\4S jrS rSr	g)ProgressCallbackWithTimeout%   zMakes progress callbacks at least once every _TIMEOUT_SECONDS.

This prevents wrong throughput calculation while not being excessively
overwhelming.
c                     X0l         X l        Xl        [        R                  " 5       U l        X@l        SU l        SU l        SU l        g)af  Initializes the callback with timeout.

Args:
  total_size: Total bytes to process. If this is None, size is not known
      at the outset.
  callback_func: Func of (int: processed_so_far, int: total_bytes)
      used to make callbacks.
  start_bytes_per_callback: Lower bound of bytes per callback.
  timeout: Number maximum of seconds without a callback.

r   N)	_bytes_per_callback_callback_func_total_sizetime
_last_time_timeout_bytes_processed_since_callback_callbacks_made_total_bytes_processed)self
total_sizecallback_funcstart_bytes_per_callbacktimeouts        *platform/gsutil/gslib/progress_callback.py__init__$ProgressCallbackWithTimeout.__init__,   s@       8'!iikDOM+,D(D"#D    c                 \   U =R                   U-  sl         [        R                  " 5       nU R                   U R                  :  dQ  U R                  b'  U R                  U R                   -   U R                  :  d  U R
                  U-
  U R                  :  a  U =R                  U R                   -  sl        U R                  b!  [        U R                  U R                  5      nOU R                  nU R                  X0R                  5        SU l         U =R                  S-  sl	        X l        gg)z@Tracks byte processing progress, making a callback if necessary.Nr   r	   )
r   r   r   r   r   r   r   minr   r   )r   bytes_processedcur_time
bytes_sents       r   Progress$ProgressCallbackWithTimeout.ProgressE   s    ((O;(yy{H,,t/G/GG				%$*E*E		-	-+.151A1A+B	8	#t}}4
!!T%I%II!
 
			%44d6F6FG
00

*&6&67-.d*
a o 	5r    )r   r   r   r   r   r   r   r   N)
__name__
__module____qualname____firstlineno____doc___START_BYTES_PER_CALLBACK_TIMEOUT_SECONDSr   r&   __static_attributes__ r    r   r   r   %   s     )B'	$2!r    r   c                   4    \ rS rSrSr      SS jrS rSrg)FileProgressCallbackHandler\   zTracks progress info for large operations like file copy or hash.

Information is sent to the status_queue, which will print it in the
UI Thread.
Nc                 f    Xl         X l        X0l        XPl        X@l        X`l        Xpl        SU l        g)a  Initializes the callback handler.

Args:
  status_queue: Queue for posting status messages for UI display.
  start_byte: The beginning of the file component, if one is being used.
  override_total_size: The size of the file component, if one is being used.
  src_url: FileUrl/CloudUrl representing the source file.
  component_num: Indicates the component number, if any.
  dst_url: FileUrl/CloudUrl representing the destination file, or None
    for unary operations like hashing.
  operation_name: String representing the operation name
FN)_status_queue_start_byte_override_total_size_component_num_src_url_dst_url_operation_name_last_byte_written)r   status_queue
start_byteoverride_total_sizesrc_urlcomponent_numdst_urloperation_names           r   r   $FileProgressCallbackHandler.__init__c   s4    ( &! 3'MM)#Dr    c                    U R                   (       a  gU R                  (       a  U R                  n[        R                  " U R                  [        UXR                  -
  U R                  [        R                  " 5       U R                  U R                  U R                  S95        U(       a  XR                  -
  U:X  a  SU l         ggg)at  Gathers information describing the operation progress.

Actual message is printed to stderr by UIThread.

Args:
  last_byte_processed: The last byte processed in the file. For file
                       components, this number should be in the range
                       [start_byte:start_byte + override_total_size].
  total_size: Total size of the ongoing operation.
N)rA   rC   rB   T)r<   r7   r   PutToQueueWithTimeoutr5   r   r6   r9   r   r8   r;   r:   )r   last_byte_processedr   s      r   call FileProgressCallbackHandler.call   s       ,,j44
+.>.>>		&*&9&9'+';'; $	/0 ),<,<<
J $d Kzr    )r8   r:   r<   r;   r7   r9   r6   r5   )r   NNNNN)r(   r)   r*   r+   r,   r   rH   r/   r0   r    r   r2   r2   \   s%     #'!"$>%r    r2   )r,   
__future__r   r   r   r   r   gslib.thread_messager   gslib.utilsr   r-   _MAX_BYTES_PER_CALLBACKr.   MAX_PROGRESS_INDICATOR_COLUMNSobjectr   r2   r0   r    r   <module>rP      sV    / & %  '  0 2 ' +   "$ 4!& 4!nD%& D%r    