
    "                     "   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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SKJr  SrSrSrS r\	R8                  R:                  4S jrS r\	R@                  " \	R8                  R:                  5      \	RB                   " S S\	RD                  5      5       5       r#\	R@                  " \	R8                  RH                  5       " S S\#5      5       r%g)zFImplementation of objects update command for updating object settings.    )absolute_import)division)unicode_literals)	cloud_api)arg_parsers)base)encryption_util)errors)flags)name_expansion)stdin_iterator)user_request_args_factory)task_executor)task_graph_executor)task_status)patch_object_task)rewrite_object_taskz
Update Cloud Storage objects.
a  
Update a Google Cloud Storage object's custom-metadata:

  $ {command} gs://bucket/my-object --custom-metadata=key1=value1,key2=value2

You can use [wildcards](https://cloud.google.com/storage/docs/wildcards)
to update multiple objects in a single command. For instance to update
all objects to have a custom-metadata key:

  $ {command} gs://bucket/** --custom-metadata=key1=value1,key2=value2

Rewrite all JPEG images to the NEARLINE storage class, including objects across
nested directories:

  $ {command} gs://bucket/**/*.jpg --storage-class=NEARLINE

You can also provide a precondition on an object's metageneration in
order to avoid potential race conditions:

  $ {command} gs://bucket/*.jpg --storage-class=NEARLINE --if-metageneration-match=123456789
ar  
The following command overwrites the custom contexts of an object:

  $ {command} gs://bucket/my-object --custom-contexts=key1=value1,key2=value2

The following example simultaneously updates and removes custom contexts, with
remove being applied first:

  $ {command} gs://bucket/my-object --update-custom-contexts=key2=value3       --remove-custom-contexts=key2,key3
c              #     #    UR                   =(       d    UR                  =(       d    UR                  nU(       a  [        R                  nO[
        R                  n[        R                  " U[        R                  R                  S9n[        R                  " U5      n[        USS5      =(       d    [        USS5      n[        USS5      =(       dI    [        USS5      =(       d5    [        USS5      =(       d!    [        USS5      =(       d    [        US	S5      nU(       d  U(       a  [        R                  R                  nOCU(       d  U(       a  [        R                  R                   nO[        R                  R"                  nUR$                  (       a?  UR&                  (       d.  UR(                  (       d  U(       d  [*        R,                  " S
5      eUR.                  (       a  [0        R2                  R4                  n	O[0        R2                  R6                  n	[0        R8                  " U U[0        R:                  R<                  [>        R@                  " U5      U	S9 H  n
U" U
RB                  US9v   M     g7f)z0Yields PatchObjectTask's or RewriteObjectTask's.)metadata_typeretain_untilNretention_modecustom_contextscustom_contexts_fileremove_custom_contextsupdate_custom_contextsclear_custom_contextsz;--all_versions flag is only allowed for ACL modifier flags.)fields_scopeinclude_bucketsobject_staterecursion_requested)user_request_args)"encryption_keyclear_encryption_keystorage_classr   RewriteObjectTaskr   PatchObjectTaskr   'get_user_request_args_from_command_argsMetadataTypeOBJECTadds_or_removes_aclsgetattrr   FieldsScopeFULLNO_ACLSHORTall_versionspredefined_aclacl_filer
   Error	recursiver   RecursionSettingYESNONameExpansionIteratorBucketSettingNO_WITH_ERRORr   get_object_state_from_flagsresource)urlsargsrequires_rewrite	task_typer!   r*   updates_retentionupdates_custom_contextsr   recursion_settingname_expansion_results              %lib/surface/storage/objects/update.py_get_task_iteratorrF   K   s     LT66L$:L:L #55I!11I  GG
7DDKKM  3GG dND9 W
d> d%t, 6	-t	46	/	66 
/	66 
.	5  -((--L3((//L((..L	
T]].B ,,EG G 
^^&77;;&77::-CC
$22@@44T:+  &&:K  s   I=I?c                    U R                  SSSS9  U R                  SSSS9  U R                  5       n[        R                  " U5        [        R                  " U5        U R                  S	[
        R                  S
S9  U R                  SSSSSS9  U R                  SSSS9  U R                  S[
        R                  SS9  [        R                  " U 5        [        R                  " U 5        [        R                  " U SS9  [        R                  " U 5        [        R                  " U SUS9  [        R                  " U SS9  [        R                  " U SS9  g)zRegister flags for this command.

Args:
  parser (argparse.ArgumentParser): The parser to add the arguments to.
  release_track (ReleaseTrack): The release track to add flags for.

Returns:
  objects update flag group
url*z$Specifies URLs of objects to update.)nargshelpz--all-versions
store_truez-Perform the operation on all object versions.)actionrK   z--event-based-holdz3Enables or disables an event-based hold on objects.z-Rz-rz--recursivezZRecursively update objects under any buckets or directories that match the URL expression.z-sz--storage-classzfSpecify the storage class of the object. Using this flag triggers a rewrite of underlying object data.)rK   z--temporary-holdz0Enables or disables a temporary hold on objects.T)allow_patch)rN   release_track)	is_updatezRead the list of objects to update from stdin. No need to enter a source argument if this flag is present.
Example: "storage objects update -I --content-type=new-type")	help_textN)add_argument	add_groupr   add_acl_modifier_flagsadd_preserve_acl_flagr   StoreTrueFalseActionadd_additional_headers_flagadd_continue_on_error_flagadd_encryption_flagsadd_precondition_flagsadd_object_metadata_flagsadd_per_object_retention_flagsadd_read_paths_from_stdin_flag)parserrO   acl_flags_groups      rE   _add_common_argsr`      sq    	3C  E 	:   $$&//o.--@  B 	

#  $ 	
.  /
 	--=  ?
 ##F+""6*V6v&!!$m &&v>&&A    c                     A g)zRegister flags for the alpha version of this command.

Args:
  parser (argparse.ArgumentParser): The parser to add the arguments to.

Returns:
  objects update flag group
N r^   s    rE   _add_alpha_argsre      s     ra   c                   8    \ rS rSrSr\\S.r\S 5       r	S r
Srg)Update   Update Cloud Storage objects.DESCRIPTIONEXAMPLESc                     [        U 5        g N)r`   rd   s    rE   ArgsUpdate.Args   s
    Vra   c           
         [         R                  " U5        UR                  (       d  UR                  c  SUl        [        R
                  " UR                  UR                  5      n[        X!5      n[        R                  R                  5       n[        R                  " USU[        R                  " [        R                   R"                  S S9UR$                  S9U l        g )NT)increment_typemanifest_path)parallelizabletask_status_queueprogress_manager_argscontinue_on_error)r	   initialize_key_storer1   preserve_aclr   get_urls_iterablerH   read_paths_from_stdinrF   r   multiprocessing_contextQueuer   execute_tasksr   ProgressManagerArgsIncrementTypeINTEGERrw   	exit_code)selfr>   r=   task_iteratorru   s        rE   Run
Update.Run   s    ((.4#4#4#<d++$,,D 't2M+CCIIK"00+)==&44<<  00DNra   )r   N)__name__
__module____qualname____firstlineno____doc___COMMAND_DESCRIPTION_GA_EXAMPLESdetailed_helpstaticmethodro   r   __static_attributes__rc   ra   rE   rg   rg      s/     & *-
  ra   rg   c                   8    \ rS rSrSr\\\-   S.r\	S 5       r
Srg)UpdateAlpha   ri   rj   c                 b    [        U [        R                  R                  5        [	        U 5        g rn   )r`   r   ReleaseTrackALPHAre   rd   s    rE   ro   UpdateAlpha.Args   s     VT..445Fra   rc   N)r   r   r   r   r   r   r   _ALPHA_EXAMPLESr   r   ro   r   rc   ra   rE   r   r      s-    % *0-
  ra   r   N)&r   
__future__r   r   r   googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   r   "googlecloudsdk.command_lib.storager	   r
   r   r   r   r   (googlecloudsdk.command_lib.storage.tasksr   r   r   0googlecloudsdk.command_lib.storage.tasks.objectsr   r   r   r   r   rF   r   GAr`   re   ReleaseTracksUniverseCompatibleCommandrg   r   r   rc   ra   rE   <module>r      s    M &  ' 4 / ( > 5 4 = = H B H @ N P ,
6r ,0+<+<+?+? ;|	 D%%(() T\\    * F D%%++,&  -ra   