
    w                         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\	R                  5      rg)z$The gcloud datastore export command.    )absolute_import)division)unicode_literals)	admin_api)
operations)base)flags)
properties)	resourcesc                   <    \ rS rSrSrSS0r\S 5       rS rS r	Sr
g	)
Export   a*  Export Cloud Datastore entities to Google Cloud Storage.

Export a copy of all or a subset of entities from Google Cloud Datastore
to another storage system, such as Google Cloud Storage. Recent
updates to entities may not be reflected in the export. The export occurs in
the background and its progress can be monitored and managed via the operation
commands.  The output of an export may only be used once the operation has
completed. If an export operation is cancelled before completion then it may
leave partial data behind in Google Cloud Storage.
EXAMPLESa            To export all kinds in the `exampleNs` namespace in the `exampleProject`
          project to the `exampleBucket`, run:

            $ {command} gs://exampleBucket --namespaces='exampleNs' --project='exampleProject'

          To export the `exampleKind` and `otherKind` kinds in the `exampleNs`
          namespace in the `exampleProject` project to the `exampleBucket`, run:

            $ {command} gs://exampleBucket --kinds='exampleKind','otherKind' --namespaces='exampleNs' --project='exampleProject'

          To export all namespaces and kinds in the currently set project to the
          `exampleBucket` without waiting for the operation to complete, run:

            $ {command} gs://exampleBucket --async

          To export the `exampleKind` in all namespaces in the currently set
          project to the `exampleBucket`, and output the result in JSON, run:

            $ {command} gs://exampleBucket --kinds='exampleKind' --format=json
      c                     [         R                  " U 5        [         R                  " U 5        U R                  SSS9  [        R
                  R                  U 5        g)z Register flags for this command.output_url_prefixa2  
        Location for the export metadata and data files. Must be a valid
        Google Cloud Storage bucket with an optional path prefix. For example:

          $ {command} gs://mybucket/my/path

        Will place the export in the `mybucket` bucket in objects prefixed with
        `my/path`.
        )helpN)r	   AddEntityFilterFlagsAddLabelsFlagadd_argumentr   
ASYNC_FLAGAddToParser)parsers    lib/surface/datastore/export.pyArgsExport.ArgsB   sO     
v&	
  
 	OO'    c                    [         R                  R                  R                  R	                  SS9nU R                  UR                  5      n[        R                  " USR                  SR                  U Vs/ s H	  oDc  M  UPM     sn5      5      UR                  UR                  UR                  S9nUR                  (       d  [        R                   " U5        U$ s  snf )NT)requiredzgs://{}/)kinds
namespaceslabels)r
   VALUEScoreprojectGet_ParseGCSObjectPrefixr   r   r   formatjoinr    r!   operation_labelsasync_r   WaitForOperation)selfargsr%   destinationpartresponses         r   Run
Export.RunT   s    $$,,00$0?G,,T-C-CDK	;K;4$;KL	Mjj??$$&H ;;!!(+O Ls   8CCc                      [         R                  R                  USS9nUR                  S4$ ! [         R                   a     Of = f[         R                  R                  USS9nUR                  UR
                  4$ )zParses a GCS bucket with an optional object prefix.

Args:
  resource: the user input resource string.
Returns:
  a tuple of strings containing the GCS bucket and GCS object. The GCS
  object may be None.
zstorage.buckets)
collectionNzstorage.objects)r   REGISTRYParsebucket	UserErrorobject)r-   resource
bucket_ref
object_refs       r   r'   Export._ParseGCSObjectPrefixf   s     %%++
0 , 2j && 
 ##)). * 0Jz0011s   +. AA N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   r2   r'   __static_attributes__r?   r   r   r   r      s6    	 
-2 ( ("$2r   r   N)rD   
__future__r   r   r    googlecloudsdk.api_lib.datastorer   r   googlecloudsdk.callioper   $googlecloudsdk.command_lib.datastorer	   googlecloudsdk.corer
   r   Commandr   r?   r   r   <module>rN      s7    + &  ' 6 7 ( 6 * )`2T\\ `2r   