
    [                      `   d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ	 ddl
mZ ddl
mZ dd	l
mZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddddZ G d dej0                        Z G d de      Z G d d      Z G d dee      Z G d dee      Zd Zd Zd  Z d! Z!y)"zGeneral utilities for copies.    )absolute_import)division)unicode_literalsN)	cloud_api)errors)manifest_util)storage_url)resource_reference)resource_util)task)
exceptions)log)
properties   Z   im  )nearlinecoldlinearchivec                   2     e Zd ZdZ	 	 	 	 d fd	Zd Z xZS )CopyTaskzHParent task that handles common attributes and an __init__ status print.c                    t         t        |           || _        || _        || _        || _        || _        || _        t        | j                  xr | j                  j                        | _        |r}| j                  r|j                  j                  }n|j                  j                  }t        j                   j#                  dj%                  ||j                  j                               yy)ay  Initializes task.

    Args:
      source_resource (resource_reference.Resource): Source resource to copy.
      destination_resource (resource_reference.Resource): Target resource to
        copy to.
      print_created_message (bool): Print a message containing the URL of the
        copy result.
      print_source_version (bool): Print source object version in status message
        enabled by the `verbose` kwarg.
      user_request_args (UserRequestArgs|None): Various user-set values
        typically converted to an API-specific RequestConfig.
      verbose (bool): Print a "copying" status message on initialization.
    zCopying {} to {}N)superr   __init___source_resource_destination_resource_print_created_message_print_source_version_user_request_args_verboseboolmanifest_path_send_manifest_messagesr	   
url_stringversionless_url_stringr   statusPrintformat)	selfsource_resourcedestination_resourceprint_created_messageprint_source_versionuser_request_argsverbosesource_string	__class__s	           <lib/googlecloudsdk/command_lib/storage/tasks/cp/copy_util.pyr   zCopyTask.__init__-   s    . 
(D"$+D!5D"7D!5D/DDM#'ID$;$;$I$I$D  		#	#'33>>'33JJ	jj

#
#"..EE     c                 z    | j                   r/t        j                  j                  dj	                  |             y y )NzCreated: {})r   r   r%   r&   r'   )r(   resources     r1   #_print_created_message_if_requestedz,CopyTask._print_created_message_if_requested\   s-    ""	jj}++H56 #r2   )FFNF)__name__
__module____qualname____doc__r   r5   __classcell__r0   s   @r1   r   r   *   s    P " -^7r2   r   c                   .     e Zd ZdZ	 	 	 	 	 d fd	Z xZS )ObjectCopyTaskzAParent task that handles common attributes for object copy tasks.c                 R    || _         || _        t        t        |   ||||||       y)a  Initializes task.

    Args:
      source_resource (resource_reference.Resource): See parent class.
      destination_resource (resource_reference.Resource): See parent class.
      posix_to_set (PosixAttributes|None): POSIX info set as custom cloud
        metadata on target.
      print_created_message (bool): See parent class.
      print_source_version (bool): See parent class.
      user_request_args (UserRequestArgs|None): See parent class.
      verbose (bool): Print a "copying" status message on initialization.
    N)_posix_to_setr   r   r=   r   )	r(   r)   r*   posix_to_setr+   r,   r-   r.   r0   s	           r1   r   zObjectCopyTask.__init__d   s8    , &D "6D	.$(r2   )NFFNF)r6   r7   r8   r9   r   r:   r;   s   @r1   r=   r=   a   s!    I ! " "r2   r=   c                       e Zd ZdZddZy)_ExitHandlerMixinz(Provides an exit handler for copy tasks.Nc                     |rj| j                   r]|s.t        j                  dj                  | j                              t        j                  || j                  | j                  |       yyy)z/Send copy result info to manifest if requested.z1Unable to send message to manifest for source: {}N)r"   command_errorsErrorr'   r   r   send_error_messager   )r(   errortask_status_queues      r1   exit_handlerz_ExitHandlerMixin.exit_handler   sh    --""?FF%%
 	

 &&'8$:O:O'+'A'A5J .ur2   )NN)r6   r7   r8   r9   rI    r2   r1   rB   rB      s    0
Jr2   rB   c                       e Zd ZdZy)CopyTaskWithExitHandlerz;Parent task with an exit handler for non-object copy tasks.Nr6   r7   r8   r9   rJ   r2   r1   rL   rL      s     Dr2   rL   c                       e Zd ZdZy)ObjectCopyTaskWithExitHandlerz7Parent task with an exit handler for object copy tasks.NrM   rJ   r2   r1   rO   rO      s    ?r2   rO   c                 $    dj                  |       S )z(Returns standardized no clobber warning.z3Skipping existing destination item (no-clobber): {})r'   )destination_urls    r1   get_no_clobber_messagerR      s    	>	E	E
 r2   c                     | r| j                   sy	 |j                  |j                  j                  |j                  j                  t
        j                  j                         y# t        j                  $ r Y yw xY w)zAReturns if cloud destination object exists if no-clobber enabled.F)fields_scopeT)

no_clobberget_object_metadatar	   bucket_nameresource_namer   FieldsScopeSHORT
api_errorsNotFoundError)r-   
api_clientr*   s      r1   check_for_cloud_clobberr^      sw      1 < <""((44((66**00 # 2 
 
	!	! s   AA& &A<;A<c                 N    | j                   | j                   S | j                  ryy)z=Prioritizes user-input generation over no-clobber zero value.Nr   )precondition_generation_matchrU   )request_configs    r1   get_generation_match_valuerb      s)    11=777	r2   c                    t        | t        j                        ryt        j                  j
                  j                  j                         rN| j                  j                  t        j                  j                  u r| j                  r| j                  t        v syt        | j                  j                            }t!        j"                  | j                        }t!        j"                  t$        j$                  j'                               }||t%        j(                  |      z   k  r;t+        j,                  dj/                  | | j                  | j                  |            y)zGRaises error if Google Cloud Storage object will incur an extra charge.N)daysaF  Deleting {} may incur an early deletion charge. Note: the source object of a mv operation is deleted.
The object appears to have been created on {}, and the minimum time before deletion for the {} storage class is {} days.
To allow deleting the object anyways, run "gcloud config set storage/check_mv_early_deletion_fee False")
isinstancer
   FolderResourcer   VALUESstoragecheck_mv_early_deletion_feeGetBoolr	   schemeProviderPrefixGCScreation_timestorage_class_EARLY_DELETION_MINIMUM_DAYSlowerr   convert_datetime_object_to_utcdatetimenow	timedeltar   rE   r'   )object_resourceminimum_lifetimecreation_datetime_utccurrent_datetime_utcs       r1   &raise_if_mv_early_deletion_fee_appliesrz      s.   !3!B!BC




#
#
?
?
G
G
I

%
%
,
,0J0J0N0N
N++

'
'+G
G
1##))+-'FF##%&EE 1H4F4F5  



J
 &/"?"? ..0@BC Cr2   )"r9   
__future__r   r   r   rs   googlecloudsdk.api_lib.storager   r   r[   "googlecloudsdk.command_lib.storagerD   r   r	   ,googlecloudsdk.command_lib.storage.resourcesr
   r   (googlecloudsdk.command_lib.storage.tasksr   googlecloudsdk.corer   r   r   rp   Taskr   r=   rB   rL   rO   rR   r^   rb   rz   rJ   r2   r1   <module>r      s    $ &  '  4 ? G < : K F 9 * # *   47tyy 47n%X %PJ J D 	D@$5~ @Cr2   