
    c                        S 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SK	J
r
  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SrSR5                  SR7                  \5      5      rSR5                  \5      rSr\\R?                  S5      -   r Sr!Sr"S\"-   \!-   r#\" \ \#5      r$\" \\!5      r%\" \\"5      r&\" / SQ0 S9r'\" / SQ0 S9r( " S S\5      r)g)z/This module provides the rpo command to gsutil.    )absolute_import)print_functionN)metrics)Command)CommandArgument)ApiSelector)CommandException)NO_URLS_MATCHED_TARGET)CreateHelpText)storage_v1_messages)NO_MAX)GcloudStorageMap)ASYNC_TURBODEFAULTz({})|z+
  gsutil rpo set {} gs://<bucket_name>...
z(
  gsutil rpo get gs://<bucket_name>...

am  
<B>SET</B>
  The ``rpo set`` command configures turbo replication
  for dual-region Google Cloud Storage buckets.

<B>SET EXAMPLES</B>
  Configure your buckets to use turbo replication:

    gsutil rpo set ASYNC_TURBO gs://redbucket gs://bluebucket

  Configure your buckets to NOT use turbo replication:

    gsutil rpo set DEFAULT gs://redbucket gs://bluebucket
z
<B>GET</B>
  The ``rpo get`` command returns the replication setting
  for the specified Cloud Storage buckets.

<B>GET EXAMPLES</B>
  Check if your buckets are using turbo replication:

    gsutil rpo get gs://redbucket gs://bluebucket
a  
  The ``rpo`` command is used to retrieve or configure the
  `replication setting
  <https://cloud.google.com/storage/docs/availability-durability#cross-region-redundancy>`_
  of dual-region Cloud Storage buckets.
  This command has two sub-commands: ``get`` and ``set``.
)storagebucketslistzL--format=value[separator=": "](format("gs://{}", name),rpo.yesno(no="None"))z--rawgcloud_commandflag_map)r   r   updatez--recovery-point-objectivec                   :   \ rS rSrSr\R                  " S/ \S\SSSS\	R                  /\	R                  \R                  " S5      /\" S\" \5      S	9\R                  " 5       /S
.S9r\R"                  " S/ SS\\\S
.S9r\" \\S
.0 S9rS rS rS rS rS rSrg)
RpoCommandc   z"Implements the gsutil rpo command.rpo    F   mode)choicesgetset)command_name_aliasesusage_synopsismin_argsmax_argssupported_sub_argsfile_url_okprovider_url_okurls_start_arggs_api_supportgs_default_apiargparse_argumentscommand_helpzConfigure replication)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textr   c                 h    UR                   R                  S:w  a  [        SU R                  -  5      eg )Ngsz7The %s command can only be used with gs:// bucket URLs.)storage_urlschemer	   command_name)selfblrs     %platform/gsutil/gslib/commands/rpo.py,_ValidateBucketListingRefAndReturnBucketName7RpoCommand._ValidateBucketListingRefAndReturnBucketName   s7    
%
C


  &    c                     UR                   nU R                  R                  UR                  S/UR                  S9nUR
                  n[        U5      R                  S5      n[        U< SU< 35        g)z"Gets the rpo setting for a bucket.r   fieldsprovider/z: N)	r:   
gsutil_api	GetBucketbucket_namer;   r   strrstripprint)r=   r>   
bucket_urlbucket_metadatar   buckets         r?   _GetRpoRpoCommand._GetRpo   si    Joo//
0F0F8=w9C9J9J 0 LO 

C_##C(F	fc
"#rB   c                 p   UR                   nUnU[        ;  a  [        SR                  [        5      5      e[
        R                  " US9nU R                  R                  SU< S[        U5      R                  S5      < 35        U R                  R                  UR                  US/UR                  S9  g)	z"Sets the rpo setting for a bucket.z.Invalid value for rpo set. Should be one of {})r   zSetting rpo z for rG   r   rD   r   )r:   VALID_RPO_VALUESr	   formatVALID_RPO_VALUES_STRINGapitools_messagesBucketloggerinforK   rL   rH   PatchBucketrJ   r;   )r=   r>   	rpo_valuerN   formatted_rpo_valuerO   s         r?   _SetRpoRpoCommand._SetRpo   s    J#"22!!'(?!@B B (..3FGOKK)3z?+A+A#+FH I 	OO
 6 6 /(-w)3):):   < rB   c           
         U R                   R                  S5      nUS;  a  [        S5      eSn/ nUS:X  a  U R                  nO>US:X  a8  U R                  nU R                   R                  S5      nUR                  U5        U R                  R                  S5      [        R                  :w  a;  [        SR                  [        R                  " S	U R                  -  5      5      5      eS
nU R                   nU(       d  U R                  5         U H  nU R                  U5      nU H  n	U R                  R                  U	R                   R"                  5      [        R                  :w  a;  [        SR                  [        R                  " SU R                  -  5      5      5      eSnU" U	/UQ76   M     M     U(       d  [        [$        ['        U5      -  5      eg)z-Handles rpo command on Cloud Storage buckets.r   r#   zrpo only supports get|setNr$   r%   r9   r   z=The "%s" command can only be with the Cloud Storage JSON API.Fz2The "%s" command can only be used for GCS buckets.T)argspopr	   rQ   r^   appendrH   GetApiSelectorr   JSONjointextwrapwrapr<   $RaiseWrongNumberOfArgumentsExceptionGetBucketUrlIterFromArgr:   r;   r
   r   )
r=   
subcommandsubcommand_funcsubcommand_argssetting_argsome_matchedurl_argsurl_strbucket_iterbucket_listing_refs
             r?   _RpoRpoCommand._Rpo   s   q!J'899OOUo	u	oIIMM!$k[) %%d+{/?/??TYY
-- %(,(9(9: ;< = =
 LyyH
//1009k +
??))**1136A6F6FG mm (+/+<+<= >"? @ @ *=_= !,  3d8nDEErB   c                     U R                   S   nU R                  SS9  US:X  d  US:X  aC  [        R                  " U R                  S9  [        R                  " U/S9  U R                  5       $ [        SU-  5      e)	z(Command entry point for the rpo command.r   T)
check_argsr$   r%   )sub_opts)subcommandsz-Invalid subcommand "%s", use get|set instead.)ra   ParseSubOptsr   LogCommandParamsrx   rt   r	   )r=   action_subcommands     r?   
RunCommandRpoCommand.RunCommand   sy    		!&E!%6%%?6,=+>?YY[L./ 0 0rB    N) __name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr   r   re   r   MakeNCloudURLsArgumentr   rT   %MakeZeroOrMoreCloudBucketURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT_get_help_text_set_help_text	help_specr   GET_COMMANDSET_COMMANDgcloud_storage_mapr@   rQ   r^   rt   r}   __static_attributes__r   rB   r?   r   r   c   s    ***!&&' %%!88;<fd3C.DECCE	,( 3#
) ( 	$(,\0rB   r   )*r   
__future__r   r   rg   gslibr   gslib.commandr   gslib.command_argumentr   gslib.cs_api_mapr   gslib.exceptionr	   r
   gslib.help_providerr   "gslib.third_party.storage_apitoolsr   rW   gslib.utils.constantsr   gslib.utils.shim_utilr   rT   rU   rf   rV   _SET_SYNOPSIS_GET_SYNOPSISlstripr   _SET_DESCRIPTION_GET_DESCRIPTION_DESCRIPTIONr   r   r   r   r   r   r   rB   r?   <module>r      s   6 & %   ! 2 ( , 2 . W ( 2-  --1A(BC 
F"#  M0066	 	   ** %Y= /?@/?@ /
 )+,  	I0 I0rB   