File: //lib/google-cloud-sdk/lib/surface/artifacts/attachments/__pycache__/download.cpython-312.pyc
�
��� � �. � d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddl m
Z
ddlmZ dd lm
Z
dd
lmZ ddlmZ ddlmZ dd
lmZ e
j( e
j* e
j, j. � G d� de
j0 � � � Zy)zAImplements the command to download attachments from a repository.� )�absolute_import)�division)�unicode_literalsN)�
exceptions)�base)�attachment_util)�
download_util)�flags)�requests)�log)�unquotec �@ � e Zd ZdZdZddd�Zed� � Zd� Zd� Z d � Z
y
)�Downloadz;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 � � t j � j | � t j � j | � | j dddd�� | j dddd �� | j d
dd�
� y)z\Set 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�Argsz
Download.ArgsC s� � �
�#�#�%�1�1�&�9� ����$�$�V�,�
����"��
%� � � ������
K� � � �����
-� � � c �� � t j j |j � |_ t j j |j � s"t j d|j z � �t j j |j � s"t j d|j z � �t j |� }| j ||j � y)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 �RunzDownload.Rund s� � � �w�w�)�)�$�*:�*:�;�D��
�7�7�>�>�$�*�*�+��0�0�
2�T�5E�5E�
E�
� � �7�7�=�=��)�)�*��/�/�
,�t�/?�/?�
?�
� � !�8�8��>�J�����j�.�.�/r! c �6 � d}|j xs |}|j xs d}|D ]� }t j j |� } t |j
dd� d � }| j ||� } t j j |j | � }
t j |
|| dt |� t |� �� t j j! dj# |j � � �� y # t $ r |}Y ��w xY w)Ni 0 � �:F)�parallelismz&Successfully downloaded the file to {})�
chunk_sizer6 r# r$ �basenamer
�rsplit�
IndexError�
get_file_name�joinr&