
    h                         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  G d
 dej                        Zy)zCCommand to export files into a Cloud Composer environment's bucket.    )absolute_import)division)unicode_literalsN)base)flags)resource_args)storage_utilc                   *    e Zd ZdZdZed        Zd Zy)Exportas  Export data from an environment into local storage or Cloud Storage.

  If the SOURCE is a directory, it and its contents are are exported
  recursively. If no SOURCE is provided, the entire contents of the
  environment's data directory will be exported. Colliding files in the
  DESTINATION will be overwritten. If a file exists in the DESTINATION but
  there is no corresponding file to overwrite it, it is untouched.

  ## EXAMPLES
  Suppose the environment `myenv`'s Cloud Storage bucket has the following
  structure:

    gs://the-bucket
    |
    +-- data
    |   |
    |   +-- file1.txt
    |   +-- file2.txt
    |   |
    |   +-- subdir1
    |   |   |
    |   |   +-- file3.txt
    |   |   +-- file4.txt

  And the local directory '/foo' has the following
  structure:

    /foo
    |
    +-- file1.txt
    +-- fileX.txt
    |   |
    |   +-- subdir1
    |   |   |
    |   |   +-- file3.txt
    |   |   +-- fileY.txt

  The following command:

    {command} myenv --destination=/foo

  would result in the following structure in the local '/foo' directory:

    /foo
    |
    +-- file1.txt
    +-- file2.txt
    +-- fileX.txt
    |   |
    |   +-- subdir1
    |   |   |
    |   |   +-- file3.txt
    |   |   +-- file4.txt
    |   |   +-- fileY.txt

  The local files '/foo/file1.txt' and '/foo/subdir1/file3.txt' will be
  overwritten with the contents of the corresponding files in the Cloud Storage
  bucket.

  If instead we had run

    {command} myenv --source=subdir1/file3.txt --destination=/foo

  the resulting local directory structure would be the following:

    /foo
    |
    +-- file1.txt
    +-- file3.txt
    +-- fileX.txt
    |   |
    |   +-- subdir1
    |   |   |
    |   |   +-- file3.txt
    |   |   +-- fileY.txt

  No local files would be overwritten since
  'gs://the-bucket/dags/subdir1/file3.txt' was written to '/foo/file3.txt'
  instead of 'foo/subdir1/file3.txt'.
  datac                     t        j                  | dd       t        j                  | t        j
                         t        j                  |        y )Nz/from whose Cloud Storage bucket to export data.F)
positional)r   AddEnvironmentResourceArgr   AddExportSourceFlagr   SUBDIR_BASEAddExportDestinationFlag)parsers    8lib/surface/composer/environments/storage/data/export.pyArgszExport.Argsq   s?    ++A 
ff&8&89	""6*    c                    t        j                  |j                  d       |j                  j                  j                         }t        j                  t        j                  |j                  xs dj                  t        j                              }t        j                  |||j                  | j                               S )Nz--source*)release_track)r	   WarnIfWildcardIsPresentsourceCONCEPTSenvironmentParse	posixpathjoinr   r   stripsepdestinationReleaseTrack)selfargsenv_refsource_paths       r   Runz
Export.Runy   s    ((jAmm''--/G..!3!3"&++"4!;!;IMM!JLK'')+ +r   N)__name__
__module____qualname____doc__r   staticmethodr   r)    r   r   r   r      s'    Ob ++ ++r   r   )r-   
__future__r   r   r   r   googlecloudsdk.callioper   #googlecloudsdk.command_lib.composerr   r   r	   Commandr   r/   r   r   <module>r4      s5    J &  '  ( 5 = <d+T\\ d+r   