
    "                        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\ -   S\-  -   r! " S S\5      r"g)z;Implementation of compose command for Google Cloud Storage.    )absolute_import)print_function)division)unicode_literals)config)BucketListingObject)Command)CommandArgument)ApiSelector)CommandException)ContainsWildcard)StorageUrlFromString)storage_v1_messages)GetEncryptionKeyWrapper)GcloudStorageFlag)GcloudStorageMap)PreconditionsFromHeaders    zb
  gsutil compose gs://bucket/source_obj1 [gs://bucket/source_obj2 ...] gs://bucket/composite_obj
z
<B>SYNOPSIS</B>
aH  


<B>DESCRIPTION</B>
  The compose command creates a new object whose content is the concatenation
  of a given sequence of source objects under the same bucket. gsutil uses
  the content type of the first source object to determine the destination
  object's content type and does not modify or delete the source objects as
  part of the compose command. For more information, see the `composite objects
  topic <https://cloud.google.com/storage/docs/composite-objects>`_.

  There is a limit (currently %d) to the number of components that can
  be composed in a single operation.
c                       \ rS rSrSr\R                  " SS/\S\S-   SSSS\	R                  \	R                  /\	R                  \R                  " 5       /S9r\R                  " SS/S	S
\0 S9r\" / SQ0 S9rS rS rSrg)ComposeCommand=   z)Implementation of gsutil compose command.composeconcat    F)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>Concatenate a sequence of objects into a new composite object.)	help_namehelp_name_aliases	help_typehelp_one_line_summary	help_textsubcommand_help_text)storageobjectsr   )gcloud_commandflag_mapc                 R    UR                   S:w  a  [        S[        U5      -  5      eg )Ngsz7"compose" called on URL with unsupported provider (%s).)schemer   str)selfurls     )platform/gsutil/gslib/commands/compose.pyCheckProviderComposeCommand.CheckProvider_   s.    
zzT
Cc#h
NP P     c           	      f   U R                   S   nU R                   SS U l         [        U5      nU R                  U5        UR                  5       (       a  [	        SU-  5      e[
        R                  " UR                  UR                  S9n/ nSnU R                    GH)  n[        U5      (       a   U R                  U5      R                  5       nO[        [        U5      5      /nU H  nUR                  n	U R                  U	5        U	R                  UR                  :w  a  [	        S5      eU(       d  U	n[
        R                  R                  U	R                  S9n
U	R                  5       (       a  [!        U	R"                  5      U
l        UR%                  U
5        ['        U5      [(        :  d  M  [	        S[(        -  5      e   GM,     U(       d  [	        S5      eU R*                  R-                  UR                  UR                  UR.                  S	S
/S9nUR0                  Ul        UR2                  Ul        [5        U R6                  =(       d    0 5      nU R8                  R;                  SU['        U5      5        U R*                  R=                  UUUUR.                  [?        [@        5      S9  g)z,Command entry point for the compose command.NzQA version-specific URL (%s) cannot be the destination for gsutil compose - abort.)namebucketz,GCS does not support inter-bucket composing.)r>   z>"compose" called with too many component objects. Limit is %d.z/"compose" requires at least 1 component object.contentEncodingcontentType)providerfieldsz)Composing %s from %d component object(s).)preconditionsrB   encryption_tuple)!argsr   r9   HasGenerationr   apitools_messagesObjectobject_namebucket_namer   WildcardIteratorIterObjectsr   storage_urlComposeRequestSourceObjectsValueListEntryint
generationappendlenMAX_COMPOSE_ARITY
gsutil_apiGetObjectMetadatar4   rA   r@   r   headersloggerinfoComposeObjectr   r   )r6   target_url_str
target_urldst_obj_metadata
componentsfirst_src_urlsrc_url_strsrc_url_iterblrsrc_urlsrc_obj_metadatafirst_src_obj_metadatarD   s                r8   
RunCommandComposeCommand.RunCommande   sy   YYr]N		#2DI%n5Jz"!! K'( ) ) )//Z5K5K7A7M7MO JMyy	+	&	&,,[9EEG+,@,MNO#//7#*"8"88 !OP
P!-,,HH(( I * 	   ""(+G,>,>(?

%*+ z?..  "9;L"M N N%  !4 NOO!__>>!!!!%%!=1	 ? 3
 $:#E#E '='M'M$,T\\-?R@MKK@*_&OO!!#""08 " :r;   )rF   N)__name__
__module____qualname____firstlineno____doc__r	   CreateCommandSpec	_SYNOPSISrU   r   XMLJSONr
   MakeZeroOrMoreCloudURLsArgumentcommand_specHelpSpec_DETAILED_HELP_TEXT	help_specr   gcloud_storage_mapr9   rg   __static_attributes__ r;   r8   r   r   =   s    1 **$: 1$!oo{'7'78 %%)IIKLN, !

J#) (6
P?:r;   r   N)#rm   
__future__r   r   r   r   botor   gslib.bucket_listing_refr   gslib.commandr	   gslib.command_argumentr
   gslib.cs_api_mapr   gslib.exceptionr   gslib.storage_urlr   r   "gslib.third_party.storage_apitoolsr   rH   gslib.utils.encryption_helperr   gslib.utils.shim_utilr   r   gslib.utils.translation_helperr   rU   ro   ru   r   ry   r;   r8   <module>r      s}    B & %  '  8 ! 2 ( , . 2 W A 3 2 C 	  $g:W g:r;   