
                         ~   d 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 ej&                  ej(                  j*                         G d dej,                               Z ej&                  ej(                  j0                         G d de             Zddde_        y)z+Command to SCP to/from a Cloud TPU VM Node.    )absolute_import)division)unicode_literals)FilesCompleter)base)flags)	ssh_utils)ssh)
propertiesc                     | j                  ddd       | j                  dt        ddd	       | j                  d
dd       | j                  ddd       | j                  ddd       y)z>Additional flags and positional args to be passed to *scp(1)*.z
--scp-flagappendzR      Additional flags to be passed to *scp(1)*. This flag may be repeated.
      )actionhelpsourceszSpecifies the files to copy.z[[USER@]INSTANCE:]SRC+)	completerr   metavarnargsdestinationz-Specifies a destination for the source files.z[[USER@]INSTANCE:]DEST)r   r   z	--recurse
store_truezUpload directories recursively.z
--compresszEnable compression.N)add_argumentr   )parsers    &lib/surface/compute/tpus/tpu_vm/scp.py
AddSCPArgsr      s    
   	)%   	:&  (
 	,-N  P 	<.C  E    c                   .    e Zd ZdZdZdZed        Zd Zy)Scp.Copy files to and from a Cloud TPU VM via SCP.Fc                     t         j                  j                  |       t        j                  || j
                  | j                         t        |       t        j                  |dd       y)z\Set up arguments for this command.

    Args:
      parser: An argparse.ArgumentParser.
    tpuscp)resource_typeoperation_typeN)
r	   BaseSSHCLIHelperArgstpu_ssh_utilsAddTPUSSHArgs_ENABLE_IAP_ENABLE_BATCHINGr   r   AddZoneFlag)clsr   s     r   r%   zScp.ArgsC   sN     ##F+9M9MNv	fE%Hr   c                    t         j                  j                  |j                        }|j                  D cg c]!  }t         j                  j                  |      # }}t         j
                  j                  ||d       |j                  xs |d   j                  }|j                  }|j                  s|D ]	  }||_         d}|j                  sd}t        j                  d      |_	        |j                  9t        j                  j                  j                  j                  d      |_        d g}t!        j"                  ||| j%                         | j&                  ||d|||
       d}	| j&                  r;|d   r6t!        j(                  |j*                  t-        |d   j.                              }	t!        j0                  |||	       y c c}w )NT)single_remoter   F)warn_on_account_user)required   )r
   FileReferenceFromPathr   r   
SCPCommandVerifyremotehostuserGetDefaultSshUsernamezoner   VALUEScomputeGetr&   PrepareNodeForSCPReleaseTrackr)   ParseBatchSize
batch_sizelen
worker_ipsSCPIntoPreppedNodes)
selfargsdstsrcsrcsr5   tpu_nameusername_requestedprepped_nodescp_batch_sizes
             r   RunzScp.RunO   s   



$
$T%5%5
6C7;||D|C&&s+|DDNN$48ZZ)47>>F{{H::#
  ;; --4Hfk yy##++0044d4Cdi6L##	 Na$33
//3|A99:n %%lD.IM Es   &GN)	__name__
__module____qualname____doc__r(   r)   classmethodr%   rM    r   r   r   r   ;   s,    6 +	I 	I(Jr   r   c                       e Zd ZdZdZdZy)ScpAlphaz6Copy files to and from a Cloud TPU VM via SCP (Alpha).TN)rN   rO   rP   rQ   r(   r)   rS   r   r   rU   rU   z   s    >+r   rU   r   a%  
        To copy a file (for example, a text file in the local home directory) to
        a Cloud TPU VM, run:

            $ {command} ~/my-file my-tpu:

        To copy a file into all workers in a Cloud TPU VM, run:

            $ {command} ~/my-file my-tpu: --worker=all

        To copy a file from a Cloud TPU VM to the home directory of the local
        computer, run:

            $ {command} my-tpu:~/my-file ~/

        To copy all files in a folder to a Cloud TPU VM, run:

            $ {command} ~/my-folder/ my-tpu: --recurse
        )briefEXAMPLESN)rQ   
__future__r   r   r   argcomplete.completersr   googlecloudsdk.callioper   "googlecloudsdk.command_lib.computer   r	   .googlecloudsdk.command_lib.compute.tpus.tpu_vmr
   r&   #googlecloudsdk.command_lib.util.sshgooglecloudsdk.corer   r   ReleaseTracksr>   GACommandr   ALPHArU   detailed_helprS   r   r   <module>rd      s    2 &  ' 2 ( 4 8 O 3 *E8 D%%(();J$,, ;J *;J| D%%++,s  - 	9		 r   