HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: //lib/google-cloud-sdk/lib/surface/artifacts/attachments/__pycache__/download.cpython-312.pyc
�

�����.�dZddlmZddlmZddlmZddlZddlmZddl	m
Z
ddlmZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZe
j(e
j*e
j,j.�Gd�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�@�eZdZdZdZddd�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��tj�j|�tj�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.)rrN)r
�GetOptionalAttachmentFlag�AddToParser�GetChunkSize�add_argument)�parsers �-lib/surface/artifacts/attachments/download.py�Argsz
Download.ArgsCs���
�#�#�%�1�1�&�9�	����$�$�V�,�
����"��
%���������
K�	�������
-�	��c���tjj|j�|_tjj	|j�s"tjd|jz��tjj|j�s"tjd|jz��tj|�}|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�RunzDownload.Runds����w�w�)�)�$�*:�*:�;�D��
�7�7�>�>�$�*�*�+��0�0�
2�T�5E�5E�
E�
���7�7�=�=��)�)�*��/�/�
,�t�/?�/?�
?�
��!�8�8��>�J�����j�.�.�/r!c�6�d}|jxs|}|jxsd}|D]�}tjj	|�}	t|j
dd�d�}|j||�}	tjj|j|	�}
tj|
||	dt|�t|���tjj!dj#|j����y#t$r|}Y��wxYw)Ni0��:F)�parallelismz&Successfully downloaded the file to {})�
chunk_sizer6r#r$�basenamer
�rsplit�
IndexError�
get_file_name�joinr&r	r�intr�status�Print�format)r/r0r.�default_chunk_sizer7r6�file�file_id�default_file_name�	file_name�
final_paths           rr-zDownload.download_filests���(�����6�$6�J��"�"�'�a�K������ � ��&�g�$�#�G�N�N�3��$:�1�$=�>���$�$�T�+<�=�i��7�7�<�<�� 0� 0�)�<�j����
�
�
�
�

�j�/��+�&�
�
�j�j���
2�
9�
9�$�:J�:J�
K��'���$�#��$�s�D
�
D�Dc�8�tj�}tj�}|j|��}|jj|�}|j�8|jjD]}|jdk(s�|jcS|S)N)�namez)artifactregistry.googleapis.com/file_name)
r�	GetClient�GetMessages�<ArtifactregistryProjectsLocationsRepositoriesFilesGetRequest�%projects_locations_repositories_files�Get�annotations�additionalProperties�key�value)r/rBrD�client�messages�request�resp�es        rr;zDownload.get_file_name�s���
�
�
�
!�F��#�#�%�H��M�M��	N�	
��
�7�7�;�;�G�D�D����#����4�4�!��5�5�?�?����.�5��r!N)�__name__�
__module__�__qualname__�__doc__�api_version�
detailed_help�staticmethodr r2r-r;�r!rrr!sB��D��+�%���-�6����@0� �6r!r)rZ�
__future__rrrr#� googlecloudsdk.api_lib.artifactsrr(�googlecloudsdk.callioper�$googlecloudsdk.command_lib.artifactsrr	r
r�googlecloudsdk.corer�six.moves.urllib.parser
�DefaultUniverseOnly�
ReleaseTracks�ReleaseTrack�GA�Commandrr^r!r�<module>rjsx��H�&��'�	�H�(�@�>�6�9�#�*��������D�%�%�(�(�)�z�t�|�|�z�*��zr!