
    |!                         d Z ddlmZ ddlmZ ddlmZ ddlZddlZ G d de      Z G d d	e      Z	 G d
 de      Z
 G d de      Z G d de      Zy)z8Messages parallel workers might send to the main thread.    )absolute_import)division)unicode_literalsNc                       e Zd ZdZy)ThreadMessagezFMessage that can be sent from multithreading workers to global status.N__name__
__module____qualname____doc__     9lib/googlecloudsdk/command_lib/storage/thread_messages.pyr   r      s    Nr   r   c                       e Zd ZdZy)IncrementProgressMessagez9Simple message indicating one of something has completed.Nr   r   r   r   r   r      s    Ar   r   c                   2    e Zd ZdZ	 	 	 	 	 	 	 ddZd Zd Zy)DetailedProgressMessageaI  Message class for sending information about operation progress.

  This class contains specific information on the progress of operating on a
  file, cloud object, or single component.

  Attributes:
    offset (int): Start of byte range to start operation at.
    length (int): Total size of file or component in bytes.
    current_byte (int): Index of byte being operated on.
    finished (bool): Indicates if the operation is complete.
    time (float): When message was created (seconds since epoch).
    source_url (StorageUrl): Represents source of data used by operation.
    destination_url (StorageUrl|None): Represents destination of data used by
      operation. None for unary operations like hashing.
    component_number (int|None): If a multipart operation, indicates the
      component number.
    total_components (int|None): If a multipart operation, indicates the
      total number of components.
    operation_name (task_status.OperationName|None): Name of the operation
      running on target data.
    error_occurred (bool): Indicates if an error occurred during the
      operation.
    process_id (int|None): Identifies process that produced the instance of this
      message (overridable for testing).
    thread_id (int|None): Identifies thread that produced the instance of this
      message (overridable for testing).
  Nc                    || _         || _        || _        || _        || _        || _        || _        || _        |	| _        |
| _	        |xs t        j                         | _        |xs t        j                         j                  | _        y)zFInitializes a ProgressMessage. See attributes docstring for arguments.N)offsetlengthcurrent_bytetime
source_urldestination_urlcomponent_numbertotal_componentsoperation_nameerror_occurredosgetpid
process_id	threadingcurrent_threadident	thread_id)selfr   r   r   r   r   r   r   r   r   r   r!   r%   s                r   __init__z DetailedProgressMessage.__init__>   s}      DKDK$DDI DO*D,D,D(D(D /BIIKDOB)":":"<"B"BDNr   c                 l    t        || j                        st        S | j                  |j                  k(  S N
isinstance	__class__NotImplemented__dict__r&   others     r   __eq__zDetailedProgressMessage.__eq__]   )    eT^^,==ENN**r   c                    dj                  | j                        }| j                  rdj                  | j                        nd}| j                  r%dj                  | j                  j                        nd}dj                  | j
                  j                  | j                  | j                  | j                  | j                  ||| j                  | j                  || j                  | j                  | j                        S );Returns a string with a valid constructor for this message.'{}'NaP  {class_name}(time={time}, offset={offset}, length={length}, current_byte={current_byte}, source_url={source_url}, destination_url={destination_url}, component_number={component_number}, total_components={total_components}, operation_name={operation_name}, error_occurred={error_occurred}, process_id={process_id}, thread_id={thread_id}))
class_namer   r   r   r   r   r   r   r   r   r   r!   r%   )formatr   r   r   valuer,   r	   r   r   r   r   r   r   r   r!   r%   )r&   source_url_stringdestination_url_stringoperation_name_strings       r   __repr__z DetailedProgressMessage.__repr__b   s    doo6/3/C/Cd**+ 
  	d))//0 	" f>>**YY{{{{&&$.....,**??..  r   )NNNNFNNr	   r
   r   r   r'   r1   r<   r   r   r   r   r   !   s/    D  $ $ $"#C>+
!r   r   c                   (    e Zd ZdZ	 	 ddZd Zd Zy)ManifestMessagea]  Message class for updating manifest file with result of copy.

  Attributes:
    source_url (StorageUrl): Source URL. Used to match information recorded by
      copy progress infra (FilesAndBytesStatusTracker).
    destination_url (StorageUrl): Destination URL.
    end_time (datetime): Date and time copy completed.
    size (int): Size of file or object.
    result_status (manifest_utils.ResultStatus): End status of copy. Either
      "OK", "skip", or "error".
    md5_hash (str|None): Hash of copied file or object.
    description (str|None): Message about something that happened during a copy.
  Nc                 f    || _         || _        || _        || _        || _        || _        || _        y)z:Initializes ManifestMessage. Args in attributes docstring.N)r   r   end_timesizeresult_statusmd5_hashdescription)r&   r   r   rA   rB   rC   rD   rE   s           r   r'   zManifestMessage.__init__   s8     !DO*DDMDI&DDM"Dr   c           
         dj                  | j                        }dj                  | j                        }dj                  | j                        }| j                  rdj                  | j                        nd}| j
                  rdj                  | j
                        nd}dj                  | j                  j                  |||| j                  | j                  ||      S )r4   r5   Nonez{class_name}(source_url={source_url}, destination_url={destination_url}, end_time={end_time}, size={size}, result_status={result_status}, md5_hash={md5_hash}, description={description}))r6   r   r   rA   rB   rC   rD   rE   )
r7   r   r   rA   rD   rE   r,   r	   rB   rC   )r&   r9   r:   end_time_stringmd5_hash_stringdescription_strings         r   r<   zManifestMessage.__repr__   s    doo6#]]4+?+?@mmDMM2O6:mmfmmDMM2O!--  39 ? AG>>22, 6(YY"00(. AG A00r   c                    t        |t        |             st        S | j                  |j                  k(  xr | j                  |j                  k(  xr | j
                  |j
                  k(  xrj | j                  |j                  k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S r)   )
r+   typer-   r   r   rA   rB   rC   rD   rE   r/   s     r   r1   zManifestMessage.__eq__   s    eT$Z(OOu/// 2  E$9$992MMU^^+204		UZZ0G2 %"5"552 MMU^^+	2
  1 113r   )NN)r	   r
   r   r   r'   r<   r1   r   r   r   r?   r?      s    ( #"0*3r   r?   c                   $    e Zd ZdZddZd Zd Zy)WorkloadEstimatorMessagezMessage class for estimating total workload of operation.

  Attributes:
    item_count (int): Number of items to add to workload estimation.
    size (int|None): Number of bytes to add to workload estimation.
  Nc                      || _         || _        y)zCInitializes WorkloadEstimatorMessage. Args in attributes docstring.N)
item_countrB   )r&   rP   rB   s      r   r'   z!WorkloadEstimatorMessage.__init__   s     !DODIr   c                 l    t        || j                        st        S | j                  |j                  k(  S r)   r*   r/   s     r   r1   zWorkloadEstimatorMessage.__eq__   r2   r   c                 z    dj                  | j                  j                  | j                  | j                        S )r4   z2{class_name}(item_count={item_count}, size={size}))r6   rP   rB   )r7   r,   r	   rP   rB   )r&   s    r   r<   z!WorkloadEstimatorMessage.__repr__   s6    ?FF>>**??YY G  r   r)   r=   r   r   r   rN   rN      s    +
r   rN   )r   
__future__r   r   r   r   r"   objectr   r   r   r?   rN   r   r   r   <module>rU      s]    ? &  ' 	 OF OB} Bbm bJ=3m =3@} r   