
                  	       H   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  \R                  \R                  " \R                  R                   5      \R"                  \R$                  " S
SS9 " S S\R&                  5      5       5       5       5       rg)z&Command to list Cloud Storage objects.    )absolute_import)division)unicode_literals)base)copying)paths)storage_parallel)logFzBThis command is deprecated. Use `gcloud alpha storage cp` instead.)
is_removedwarningc                   8    \ rS rSrSrSSS.r\S 5       rS rSr	g	)
Copy   z1Upload, download, and copy Cloud Storage objects.z}      Copy files between your local file system and Cloud Storage or from one
      Cloud Storage location to another.
      a  
      Uploading files:

        To upload a single file to a remote location:

          $ *{command}* path/to/file.txt gs://mybucket/file.txt
          $ *{command}* path/to/file.txt gs://mybucket/

        The above two commands both create gs://mybucket/file.txt.

        To upload multiple files to a remote location:

          $ *{command}* path/to/a.txt other/path/b.txt gs://mybucket/remote-dir/

        The above command will create gs://mybucket/remote-dir/a.txt and
        gs://mybucket/remote-dir/b.txt. If remote-dir does not exist, this command will create
        remote-dir.

        To upload a directory my-dir and all its sub-directories and files:

          $ *{command}* --recursive my-dir gs://mybucket/remote-dir/

        If my-dir has a subdirectory sub-dir and sub-dir has a file a.txt, the above
        command will create gs://mybucket/remote-dir/my-dir/sub-dir/a.txt. The structure of directory
        is kept.

        The following command also uploads all files in my-dir and sub-directories recursively:

          $ *{command}* my-dir/** gs://mybucket/remote-dir/

        The above command flattens the directory strucutre and creates gs://mybucket/remote-dir/a.txt.

        To upload all files in a directory, ignoring the subdirectories:

          $ *{command}*  my-dir/* gs://mybucket/remote-dir/

        If my-dir has a file a.txt and a subdirectory sub-dir. The above command will ceate
        gs://mybucket/remote-dir/a.txt.

        We can combine the wildcards to upload all text files in a directory and all subdirectories
        recursively:

          $ *{command}*  my-dir/**/*.txt gs://mybucket/remote-dir/

      Downloading files:

        To download a single file:

          $ *{command}* gs://mybucket/file.txt local-dir/
          $ *{command}* gs://mybucket/file.txt local-dir/file.txt

        The above two commands both create local-dir/file.txt.

        To download multiple files:

          $ *{command}* gs://mybucket/a.txt gs://mybucket/b.txt local-dir/

        The above command creates local-dir/a.txt and local-dir/b.txt.

        To download a directory and all its sub-directories and files:

          $ *{command}* --recursive gs://mybucket/remote-dir/ local-dir/

        The above command creates local-dir/remote-dir/ which contains all files and subdirectories
        of gs://mybucket/remote-dir/. The structure of directory is kept.

        The following command also downloads all files in gs://mybucket/remote-dir/ to local-dir:

          $ *{command}* gs://mybucket/remote-dir/** local-dir/

        If remote-dir contains files a.txt and sub-dir/b.txt, the above command flattens the
        directory structure and creates local-dir/a.txt and local-dir/b.txt.

        To download all files, ignoring the subdirectories::

          $ *{command}* gs://mybucket/remote-dir/* local-dir/

        We can combine the wildcards to download all text files under remote-dir and its
        subdirectories:

          $ *{command}* gs://mybucket/remote-dir/**/*.txt local-dir/

      Coping between Cloud Storage locations:

        To copy a single file to another location:

          $ *{command}* gs://mybucket/file.txt gs://otherbucket/file.txt
          $ *{command}* gs://mybucket/file.txt gs://otherbucket/

        The above two commands both create gs://otherbucket/file.txt.

        To copy multiple files to a new location:

          $ *{command}* gs://mybucket/a.txt gs://mybucket/b.txt gs://otherbucket/target-dir/

        The above command creates gs://otherbucket/target-dir/a.txt and
        gs://otherbucket/target-dir/b.txt. If target-dir does not exist, this command will create
        target-dir.

        To copy all files and subdirectories in one location to another:

          $ *{command}* --recursive gs://mybucket/source-dir/ gs://otherbucket/target-dir/

        If source-dir has a subdirectory sub-dir and sub-dir has a file a.txt, the above
        command will create gs://mybucket/target-dir/source-dir/sub-dir/a.txt. The structure of
        directory is kept.

        The following command also copies all files in source-dir and its sub-directories:

          $ *{command}* gs://mybucket/source-dir/** gs://mybucket/target-dir/

        The above command flattens the directory strucutre and creates gs://mybucket/target-dir/a.txt.

        To copy all files in a directory, ignoring the subdirectories:

          $ *{command}* gs://mybucket/source-dir/* gs://mybucket/target-dir/

        If source-dir has a file a.txt and a subdirectory sub-dir. The above command will ceate
        gs://mybucket/target-dir/a.txt.

        We can combine the wildcards to copy all text in one location and all its sub-directories:

          $ *{command}* gs://mybucket/source-dir/**/*.txt gs://mybucket/target-dir/
      )DESCRIPTIONEXAMPLESc                     U R                  SSSS9  U R                  SSS9  U R                  SS	S
S9  U R                  S[        SSSS9  g )Nsource+zThe source file to copy.)nargshelpdestinationz$The destination to copy the file to.)r   z--recursive
store_truezPRecursively copy the contents of any directories that match the path expression.)actionr   z--num-threadsT   z*The number of threads to use for the copy.)typehiddendefaultr   )add_argumentint)parsers    lib/surface/storage/copy.pyArgs	Copy.Args   s}    
'  ) 3  5    !
 9  ;    c                    UR                    Vs/ s H  n[        R                  " U5      PM     nn[        R                  " UR                  5      n[        R
                  " 5       nUR                  X4UR                  S9n[        R                  " XaR                  SS9  [        R                  R                  SR                  [        U5      [        U5      S:  a  SOS5      5        g s  snf )N)	recursivezCopying Files)num_threadsprogress_bar_labelzCopied [{}] file{}.
   s )r   r   Pathr   r   CopyTaskGeneratorGetCopyTasksr&   r	   ExecuteTasksr'   r
   statuswriteformatlen)selfargspsourcesdestcopiertaskss          r!   RunCopy.Run   s    &*kk2kuzz!}kG2::d&&'D&&(FHE!!++QJJ,33E
3u:>Cr3 4 3s    C) N)
__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr"   r;   __static_attributes__r=   r$   r!   r   r      s4     :
|
B-H ; ;(	4r$   r   N)rB   
__future__r   r   r   googlecloudsdk.callioper   "googlecloudsdk.command_lib.storager   r   r	   googlecloudsdk.corer
   HiddenReleaseTracksReleaseTrackALPHAUniverseCompatible	DeprecateCommandr   r=   r$   r!   <module>rQ      s     - &  ' ( 6 4 ? # D%%++,5 +9 :e44<< e4:  - 
e4r$   