
    P                        S r SSKJr  SSKJr  SSKJr  SSK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       " S S\
R*                  5      5       5       rg)z!Download Artifact Registry files.    )absolute_import)division)unicode_literalsN)
exceptions)base)download_util)	file_util)flags)logc                   >    \ rS rSrSrSSS.r\S 5       rS rS r	S	r
g
)Download   z]Download an Artifact Registry file.

Downloads an Artifact Registry file based on file name.
z{description}aS        To download a file named `myfile` in project `my-project` under repository `my-repo` in `us-central1` to the local path `~/`:

          $ {command} --location=us-central1 --project=my-project --repository=my-repo --destination=~/ myfile

      To download a file named `myfile` in project `my-project` under repository `my-repo` in `us-central1` to the local path `~/` using parallel multipart download with 4 threads:

          $ {command} --location=us-central1 --project=my-project --repository=my-repo --destination=~/ --parallelism=4 myfile

      To download a file named `myfile` in project `my-project` under repository `my-repo` in `us-central1` to the local path `~/` with file overwriting enabled:

          $ {command} --location=us-central1 --project=my-project --repository=my-repo --destination=~/ myfile --allow-overwrite
    )DESCRIPTIONEXAMPLESc                     [         R                  " 5       R                  U 5        [         R                  " 5       R                  U 5        U R	                  SSSSS9  U R	                  SSSS	9  U R	                  S
SSS	9  g )Nz--destinationDESTINATIONTz9            The path where you want to download the file.)metavarrequiredhelpz--local-filenameLOCAL_FILENAMEzIf specified, the name of the downloaded file on the local system is set to the value you use for LOCAL_FILENAME. Otherwise the name of the downloaded file is based on the file name in the registry.)r   r   z--parallelismPARALLELISMzLSpecifies the number of threads to use for downloading the file in parallel.)r
   GetRequiredFileFlagAddToParserGetAllowOverwriteFlagadd_argument)parsers    'lib/surface/artifacts/files/download.pyArgsDownload.Args8   s    	++F3	!--f5
=	    	  	 	      c           
         [         R                  " UR                  R                  R	                  5       5      nUR
                  (       a  UR
                  OU R                  UR                  5      nUR                  =(       d    Sn[        R                  R                  UR                  U5      n[        R                  R                  U5      n[        R                  R                  U5      n[        R                  R                  U5      (       d  [         R"                  " SU-   5      e[        R                  R%                  U5      (       d  [         R&                  " SU-   5      eSn[(        R*                  " UUR-                  5       UUR.                  U[1        U5      5        [2        R4                  R7                  SUR                  -   5        g)zRun the file download command.   z&Destination directory does not exist: z Destination is not a directory: i  0 z$Successfully downloaded the file to N)r	   EscapeFileNameCONCEPTSfileParselocal_filenameos_friendly_filenamefilesIdparallelismospathjoindestination
expanduserdirnameexistsar_exceptionsDirectoryNotExistErrorisdirPathNotDirectoryErrorr   r   RelativeNameallow_overwriteintr   statusPrint)selfargsfile_escapedfilenamer*   
final_pathdest_dirdefault_chunk_sizes           r   RunDownload.RunV   sb    ++DMM,>,>,D,D,FGL  	&&|';';< 
 ""'aKd..9J##J/Jwwz*H77>>(##00
2X
=  77==""//
,x
7  )!!#K JJ;d>N>NNOr    c                    UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	S
5      nUR                  SS5      nUR                  SS5      nU$ )N:z%3A\z%5C*z%3F?z%22<z%3C>z%2E|z%7C)replace)r;   file_idr>   s      r   r(   Download.os_friendly_filenamew   s    sE*He,HU+HU+HU+HU+HU+HOr     N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr   rB   r(   __static_attributes__rO   r    r   r   r      s8     %-"  :PBr    r   )rT   
__future__r   r   r   r+    googlecloudsdk.api_lib.artifactsr   r2   googlecloudsdk.callioper   $googlecloudsdk.command_lib.artifactsr   r	   r
   googlecloudsdk.corer   DefaultUniverseOnlyReleaseTracksReleaseTrackGACommandr   rO   r    r   <module>rb      so    ( &  ' 	 H ( > : 6 # D%%(()^t|| ^ * ^r    