
                            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ZdZdZe	j2                   e	j4                  e	j6                  j8                         G d de	j:                                      Z e	j4                  e	j6                  j>                         G d de             Z y)z<Implementation of objects compose command for Cloud Storage.    )absolute_import)division)unicode_literalsN)	cloud_api)base)encryption_util)errors)errors_util)flags)name_expansion)storage_url)user_request_args_factory)resource_reference)compose_objects_taskad  
{command} creates a new object whose content is the concatenation
of a given sequence of source objects in the same bucket.
For more information, please see:
[composite objects documentation](https://cloud.google.com/storage/docs/composite-objects).

There is a limit (currently 32) to the number of components
that can be composed in a single operation.
z
The following command creates a new object `target.txt` by concatenating
`a.txt` and `b.txt`:

  $ {command} gs://bucket/a.txt gs://bucket/b.txt gs://bucket/target.txt

c                   0    e Zd ZdZeedZed        Zd Z	y)Compose>Concatenate a sequence of objects into a new composite object.DESCRIPTIONEXAMPLESc                    |j                  ddt        j                  d             |j                  dd       t        j                  |       t        j
                  |d	       t        j                  |       t        j                  |       | j                         t        j                  j                  k(  r+t        j                  |      }t        j                  |       y y )
Nsource+zb            The list of source objects that will be concatenated into a
            single object.)nargshelpdestinationzThe destination object.)r   T)hidden)add_argumenttextwrapdedentr   add_additional_headers_flagadd_encryption_flagsadd_per_object_retention_flagsadd_precondition_flagsReleaseTrackr   ALPHAget_object_context_groupadd_object_context_setter_flags)clsparsercontext_groups      &lib/surface/storage/objects/compose.pyArgszCompose.ArgsB   s    
__      ,EF	%%f-	vd3	((0	  (
T..44444V<m++M: 5    c                    t        j                  |       |j                  rt        j                  t        j                  |j                              }|j                  D ]n  }t        j                  |      }t        j                  |j                  |       |j                  |j
                  j                  us[t        j                  d       |j                  j
                  j                  k7  rt        j                  d      t        j                   |j                  t"        j$                  j&                  t        j(                  j*                        }|D cg c]  }|j,                   }}t/        j0                  |t.        j2                  j4                        }t7        j8                  ||d|      j;                          y c c}w )Nz,Composing across providers is not supported.zVerison-specific URLs are not valid destinations because composing always results in creating an object with the latest generation.)fields_scoperecursion_requested)metadata_typeT)print_status_messageuser_request_args)r   initialize_key_storer   r   UnknownResourcer   storage_url_from_stringr   r
   raise_error_if_not_cloud_objectcommand_pathschemer	   Errorversionless_url_stringr   NameExpansionIteratorr   FieldsScopeNO_ACLRecursionSettingNOresourcer   'get_user_request_args_from_command_argsMetadataTypeOBJECTr   ComposeObjectsTaskexecute)	selfargsdestination_resource
url_string
source_urlsource_expansion_iteratorr   objects_to_composer5   s	            r-   RunzCompose.RunU   s   ((.{{/??

-
-d.>.>
?A* 88D
33D4E4E4>	@$8$D$D$K$KKKL
L $ 	((??	@LL ! !
 !/ D D**11*;;>>!@ '@&?F&?  
 	"II 9 F F M M	O  ++!+	
 gis   GN)
__name__
__module____qualname____doc___COMMAND_DESCRIPTION_GA_EXAMPLESdetailed_helpclassmethodr.   rP    r/   r-   r   r   8   s0     G *-
 ; ;$$r/   r   c                        e Zd ZdZeeez   dZy)ComposeAlphar   r   N)rQ   rR   rS   rT   rU   rV   _ALPHA_EXAMPLESrW   rY   r/   r-   r[   r[   |   s    F *0-r/   r[   )!rT   
__future__r   r   r   r    googlecloudsdk.api_lib.storager   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   r	   r
   r   r   r   r   ,googlecloudsdk.command_lib.storage.resourcesr   (googlecloudsdk.command_lib.storage.tasksr   rU   rV   r\   UniverseCompatibleReleaseTracksr&   GACommandr   r'   r[   rY   r/   r-   <module>rg      s    C &  '  4 ( > 5 : 4 = : H K I  D%%(()?dll ? * ?D D%%++,7  -r/   