
                         .   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  SSKJr  SSKJr  \
R(                  \
R*                  " \
R,                  R.                  5       " S S\
R0                  5      5       5       rg)zAImplements the command to download attachments from a repository.    )absolute_import)division)unicode_literalsN)
exceptions)base)attachment_util)download_util)flags)requests)log)unquotec                   H    \ rS rSrSrSrSSS.r\S 5       rS r	S	 r
S
 rSrg)Download!   z;Download an Artifact Registry attachment from a repository.v1z{description}a      To download the attachment `my-attachment` to `/path/to/destination/`:

        $ {command} my-attachment --destination=/path/to/destination/

    To download the attachment `my-attachment` in 8000 byte chunks to `/path/to/destination/`:

        $ {command} my-attachment --destination=/path/to/destination/             --chunk-size=8000

    To download the attachment `my-attachment` using parallel multipart download with 4 threads:

        $ {command} my-attachment --destination=/path/to/destination/             --parallelism=4

    For Docker-format repositories only: to download the attachment stored in the OCI version `projects/my-project/locations/us/repositories/my-repo/packages/my-package/versions/sha256:123` to `/path/to/destination/`:

        $ {command} --oci-version-name=projects/my-project/locations/us/repositories/my-repo/packages/my-package/versions/sha256:123 --destination=/path/to/destination/

    For Docker-format repositories only: to download the attachment stored in the OCI version with URI `us-docker.pkg.dev/my-project/my-repo/my-package@sha256:123` to `/path/to/destination/`:

        $ {command} --oci-version-name=us-docker.pkg.dev/my-project/my-repo/my-package@sha256:123 --destination=/path/to/destination/
    )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	S9  U R	                  S
SSS9  g)zPSet up arguments for this command.

Args:
  parser: An argparse.ArgumentParser.
z--oci-version-nameOCI_VERSION_NAMEFzVFor Docker-format repositories only. The version name of the OCI artifact to download.)metavarrequiredhelpz--destinationDESTINATIONTz<Path where you want to save the downloaded attachment files.z--parallelismPARALLELISMzXSpecifies the number of threads to use for downloading the attachment files in parallel.)r   r   N)r
   GetOptionalAttachmentFlagAddToParserGetChunkSizeadd_argument)parsers    -lib/surface/artifacts/attachments/download.pyArgsDownload.ArgsC   s     
##%11&9	$$V,
"%   K	   -	      c                    [         R                  R                  UR                  5      Ul        [         R                  R	                  UR                  5      (       d#  [
        R                  " SUR                  -   5      e[         R                  R                  UR                  5      (       d#  [
        R                  " SUR                  -   5      e[        R                  " U5      nU R                  XR                  5        g)z%Runs the attachment download command.z&Destination directory does not exist: z Destination is not a directory: N)ospath
expanduserdestinationexistsar_exceptionsDirectoryNotExistErrorisdirPathNotDirectoryErrorr   GetAttachmentToDownloaddownload_filesfiles)selfargs
attachments      r    RunDownload.Rund   s     ww))$*:*:;D77>>$**++00
2T5E5E
E  77==))**//
,t/?/?
?  !88>J../r#   c                 J   SnUR                   =(       d    UnUR                  =(       d    SnU H  n[        R                  R	                  U5      n [        UR                  SS5      S   5      nU R                  Xh5      n	[        R                  R                  UR                  U	5      n
[        R                  " U
UU	S[        U5      [        U5      S9  [        R                  R!                  SR#                  UR                  5      5        M     g ! [         a    Un Nf = f)Ni  0    :F)parallelismz&Successfully downloaded the file to {})
chunk_sizer9   r%   r&   basenamer   rsplit
IndexErrorget_file_namejoinr(   r	   r   intr   statusPrintformat)r1   r2   r0   default_chunk_sizer:   r9   filefile_iddefault_file_name	file_name
final_paths              r    r/   Download.download_filest   s    (6$6J""'aK   &g$#GNN3$:1$=> $$T=i77<< 0 0)<j




j/+& 
jj
2
9
9$:J:J
K'   $#$s   DD"!D"c                 >   [         R                  " 5       n[         R                  " 5       nUR                  US9nUR                  R                  U5      nUR                  b;  UR                  R                   H!  nUR                  S:X  d  M  UR                  s  $    U$ )N)namez)artifactregistry.googleapis.com/file_name)
r   	GetClientGetMessages<ArtifactregistryProjectsLocationsRepositoriesFilesGetRequest%projects_locations_repositories_filesGetannotationsadditionalPropertieskeyvalue)r1   rE   rG   clientmessagesrequestrespes           r    r>   Download.get_file_name   s    !F##%HMM 	N 	
 
 77;;GDD#44!55??. 5 r#    N)__name__
__module____qualname____firstlineno____doc__api_versiondetailed_helpstaticmethodr!   r4   r/   r>   __static_attributes__r\   r#   r    r   r   !   sB     D+ %-6  @0 6r#   r   )ra   
__future__r   r   r   r%    googlecloudsdk.api_lib.artifactsr   r*   googlecloudsdk.callioper   $googlecloudsdk.command_lib.artifactsr   r	   r
   r   googlecloudsdk.corer   six.moves.urllib.parser   DefaultUniverseOnlyReleaseTracksReleaseTrackGACommandr   r\   r#   r    <module>rq      sv    H &  ' 	 H ( @ > 6 9 # * D%%(()zt|| z * zr#   