
    N                         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)ExportaZ  Export DAGs 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 DAGs 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
    |
    +-- dags
    |   |
    |   +-- file1.py
    |   +-- file2.py
    |   |
    |   +-- subdir1
    |   |   |
    |   |   +-- file3.py
    |   |   +-- file4.py

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

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

  The following command:

    {command} myenv --destination=/foo

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

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

  The local files '/foo/file1.py' and '/foo/subdir1/file3.py' 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.py --destination=/foo

  the resulting local directory structure would be the following:

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

  No local files would be overwritten since
  'gs://the-bucket/dags/subdir1/file3.py' was written to '/foo/file3.py'
  instead of 'foo/subdir1/file3.py'.
  dagsc                     t        j                  | dd       t        j                  | t        j
                         t        j                  |        y )Nz.from whose Cloud Storage bucket to export DAGsF)
positional)r   AddEnvironmentResourceArgr   AddExportSourceFlagr   SUBDIR_BASEAddExportDestinationFlag)parsers    8lib/surface/composer/environments/storage/dags/export.pyArgszExport.Argsq   s?    ++@ 
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   