
    "                     p   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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r \\ RC                  S5      -   S-   r"Sr#Sr$S\#-   \$-   S-   r%\" \"\%5      r&\" \\#5      r'\" \ \$5      r( " S S\
5      r)g)zBImplementation of lifecycle configuration command for GCS buckets.    )absolute_import)print_function)division)unicode_literalsN)metrics)Command)CommandArgument)ApiSelector)CommandException)NO_URLS_MATCHED_TARGET)CreateHelpText)UrlsAreForSingleProvider)storage_v1_messages)NO_MAX)GcloudStorageMap)LifecycleTranslationz+
  gsutil lifecycle get gs://<bucket_name>
zA
  gsutil lifecycle set <config-json-file> gs://<bucket_name>...

aP  
<B>GET</B>
  Gets the lifecycle management configuration for a given bucket. You can get the
  lifecycle management configuration for only one bucket at a time. To update the
  configuration, you can redirect the output of the ``get`` command into a file,
  edit the file, and then set it on the bucket using the ``set`` sub-command.

z
<B>SET</B>
  Sets the lifecycle management configuration on one or more buckets. The ``config-json-file``
  specified on the command line should be a path to a local file containing
  the lifecycle configuration JSON document.

aG  
  You can use the ``lifecycle`` command to get or set lifecycle management policies
  for a given bucket. This command is supported for buckets only, not
  objects. For more information, see `Object Lifecycle Management
  <https://cloud.google.com/storage/docs/lifecycle>`_.

  The ``lifecycle`` command has two sub-commands:
a  
<B>EXAMPLES</B>
  The following lifecycle management configuration JSON document specifies that all objects
  in this bucket that are more than 365 days old are deleted automatically:

    {
      "rule":
      [
        {
          "action": {"type": "Delete"},
          "condition": {"age": 365}
        }
      ]
    }

  The following empty lifecycle management configuration JSON document removes all
  lifecycle configuration for a bucket:

    {}

c                   T  ^  \ rS rSrSr\R                  " SS/\S\SSSS	\	R                  \	R                  /\	R                  \R                  " S	5      \R                  " 5       /\R                  " S	5      /S
.S9r\R"                  " SSS/SS\\\S.S9rU 4S jrS rS rS rSrU =r$ )LifecycleCommandc   z+Implementation of gsutil lifecycle command.	lifecyclelifecycleconfig    TF   )setget)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getlifecyclesetlifecyclecommand_helpz/Get or set lifecycle configuration for a bucket)r   r   )	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_textc                 &  > U R                   S   S:X  aY  [        S[        SSSSR                  U R                   S   5      /U R                   SS  -   0 S	900 S	9nU R                   S S U l         O[        S
[        / SQ0 S	900 S	9n[        TU ]  U5      $ )Nr   r   storagebucketsupdatez--lifecycle-file={}r   r   )gcloud_commandflag_mapr   )r3   r4   describezo--format=gsutiljson[key=lifecycle_config,empty=' has no lifecycle configuration.',empty_prefix_key=storage_url])argsr   formatsuperget_gcloud_storage_args)selfgcloud_storage_map	__class__s     +platform/gsutil/gslib/commands/lifecycle.pyr<   (LifecycleCommand.get_gcloud_storage_args   s    yy|u+"##"/66tyy|D	&
 ))AB-&(  "   ))BQ-di+"&  "   7*+=>>    c           	         U R                   S   nU R                   SS n[        U5      (       d  [        SU R                  -  5      e[	        US5      nUR                  5       nUR                  5         SnU H  nU R                  US/S9nU H  nUR                  n	S	nU R                  R                  S
U5        U	R                  S:X  a'  U R                  R                  UU	U	R                  S9  Md  [        R                  " U5      n
[         R"                  " U
S9nU R                  R%                  U	R&                  UU	R                  S/S9  M     M     U(       d  [        [(        [+        U5      -  5      eg)z?Sets lifecycle configuration for a Google Cloud Storage bucket.r   r   Nz,"%s" command spanning providers not allowed.rFr   bucket_fieldsTz(Setting lifecycle configuration on %s...s3provider)r   id)rI   fields)r9   r   r   command_nameopenreadcloseGetBucketUrlIterFromArgstorage_urlloggerinfoscheme
gsutil_apiXmlPassThroughSetLifecycler   JsonLifecycleToMessageapitools_messagesBucketPatchBucketbucket_namer   list)r=   lifecycle_argurl_argslifecycle_filelifecycle_txtsome_matchedurl_strbucket_iterblrurlr   bucket_metadatas               r@   _SetLifecycleConfig$LifecycleCommand._SetLifecycleConfig   se   IIaLMyy}H#H--K!../ 0 0 --N"'')M L00@K} 1 Nk#ooCSI::
//
4
4]58>Ajj 5 J +AA-P)-44yI/
//
%
%coo&5/2zz.2V & 5  $ 3d8nDEErB   c                    U R                  U R                  S   S/S9u  pUR                  S:X  aA  [        R                  R                  U R                  R                  XR                  S95        gUR                  (       aY  UR                  R                  (       a>  [        R                  R                  [        R                  " UR                  5      5        g[        R                  R                  SU-  5        g)z?Gets lifecycle configuration for a Google Cloud Storage bucket.r   r   rE   rG   rH   z#%s has no lifecycle configuration.
)GetSingleBucketUrlFromArgr9   rT   sysstdoutwriterU   XmlPassThroughGetLifecycler   ruler   JsonLifecycleFromMessage)r=   
bucket_urlrf   s      r@   _GetLifecycleConfig$LifecycleCommand._GetLifecycleConfig   s    "&"@"@		![M #A #3J D 	jj
//
4
4#4#4 5 67  
	"	"'@'@'E'E

 99))+	,  	

?*LMrB   c                     U R                   R                  S5      nUS:X  a%  [        R                  " U/S9  U R	                  5       $ US:X  a%  [        R                  " U/S9  U R                  5       $ [        SU< SU R                  < S35      e)z.Command entry point for the lifecycle command.r   r   )subcommandsr   zInvalid subcommand "z
" for the z	 command.)r9   popr   LogCommandParamsrr   rg   r   rL   )r=   
subcommands     r@   
RunCommandLifecycleCommand.RunCommand   s    q!JUJ<8%%''	u	J<8%%''($*;*;= > >rB   )r9   )__name__
__module____qualname____firstlineno____doc__r   CreateCommandSpec	_SYNOPSISr   r
   JSONXMLr	   MakeNFileURLsArgument%MakeZeroOrMoreCloudBucketURLsArgumentMakeNCloudBucketURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT_get_help_text_set_help_text	help_specr<   rg   rr   ry   __static_attributes____classcell__)r?   s   @r@   r   r   c   s    3 **-.



// !%% 33A6CCE ">>qAC	,. 

 N#)$?L$L&> >rB   r   )*r   
__future__r   r   r   r   rk   gslibr   gslib.commandr   gslib.command_argumentr	   gslib.cs_api_mapr
   gslib.exceptionr   r   gslib.help_providerr   gslib.storage_urlr   "gslib.third_party.storage_apitoolsr   rX   gslib.utils.constantsr   gslib.utils.shim_utilr   gslib.utils.translation_helperr   _GET_SYNOPSIS_SET_SYNOPSISlstripr   _GET_DESCRIPTION_SET_DESCRIPTION_DESCRIPTIONr   r   r   r    rB   r@   <module>r      s    I & %  ' 
  ! 2 ( , 2 . 6 W ( 2 ? M0066=	    **-: %Y= /?@/?@T>w T>rB   