%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3.9/site-packages/ansible/galaxy/collection/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3.9/site-packages/ansible/galaxy/collection/__pycache__/__init__.cpython-39.pyc

a

�)g�'�@s�dZddlmZmZmZeZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlmZddlmZddlmZmZddl m!Z!ddl"m#Z#dd	l$m%Z%dd
l&m'Z'zddl(m)Z*Wn&e+�y*Gdd
�d
�Z*dZ,Yn0dZ,zddl-m.Z.ddl/m0Z0Wne+�yddZ1Yn0dZ1ej2�r4ddl3m4Z4ej5dZ6ej5dZ7ej5dddddddddddd d!d"e7fZ8ej9e8ej:e;e<ej=e<ej9e<e<fdffZ>ej9e6e>fZ?ej9e7ej:e<e;dffZ@ej9ej5d#ej:ej=e@e;ffZAddlBmCZDdd$lEmFZFdd%lGmHZHdd&l3mIZImJZJmKZKmLZLmMZMdd'lNmOZOdd(lPmQZQmRZRmSZSmTZTz4dd)lUmVZVdd*lWmXZXmYZYdd+lZm[Z[m\Z\m]Z]Wne+�y�dZ^Yn0dZ^dd,l_m`Z`m)Z)maZadd-lbmcZcdd.ldmeZedd/lfmgZgdd0lhmiZimjZjmkZkdd1llmmZmdd2lnmoZodd3lpmqZqdd4lrmsZsdd5ltmuZumvZvdd6lwmxZxes�ayd7Zzd8Z{ed9gd:��Z|d;Z}eGd<d=�d=��Z~Gd>d?�d?e�Z�Gd@dA�dA�Z�dBdC�Z�dDdE�Z�dFdG�Z�dHdI�Z�dJdK�Z�dLdM�Z�dNdO�Z�dPdQ�Z�dRdS�Z�dTdU�Z�edVdW��Z�ed�dXdY��Z�dZd[�Z�d\d]�Z�d�d_d`�Z�dadb�Z�dcdd�Z�dedf�Z�dgdh�Z�didj�Z�dkdl�Z�dmdn�Z�dodp�Z�dqdr�Z�dsdt�Z�dudv�Z�dwdx�Z�dydz�Z�d�d{d|�Z�d}d~�Z�dd��Z�d�d��Z�d�d��Z�d�d�d��Z�d�d��Z�dS)�z)Installed collections management package.�)�absolute_import�division�print_functionN)�
namedtuple)�contextmanager)�	dataclass�fields)�sha256)�BytesIO)�distribution)�chain)�Requirementc@seZdZdS)�PkgReqN)�__name__�
__module__�__qualname__�rr�F/usr/lib/python3.9/site-packages/ansible/galaxy/collection/__init__.pyr%srFT)�Manifest)�DistlibException)�ConcreteArtifactsManager��collection_info�file_manifest_file�format��name�ftype�chksum_type�
chksum_sha256r�	namespacer�version�authors�readme�tags�description�license�license_file�dependencies�
repository�
documentation�homepage�issues��filesr)�AnsibleError)�	GalaxyAPI)�
_consume_file�_download_file�_get_json_from_installed_dir�_get_meta_from_src_dir�_tarfile_extract)�MultiGalaxyAPIProxy)�run_gpg_verify�parse_gpg_errors�get_signature_from_source�
GPG_ERROR_MAP)�$build_collection_dependency_resolver)�(CollectionDependencyResolutionImpossible�)CollectionDependencyInconsistentCandidate)�RESOLVELIB_VERSION�RESOLVELIB_LOWERBOUND�RESOLVELIB_UPPERBOUND)�	Candidater
�_is_installed_collection_dir)�meets_requirements)�get_all_plugin_loaders)�
raise_from)�to_bytes�	to_native�to_text)�is_sequence)�	yaml_dump)�AnsibleCollectionRef)�Display)�secure_hash�
secure_hash_s)�Sentinel�z
MANIFEST.json�ModifiedContent��filename�expected�	installedz0^(?P<strict>\+)?(?:(?P<count>\d+)|(?P<all>all))$cs:eZdZUdZeeed<dZeed<�fdd�Z	�Z
S)�ManifestControlN�
directivesF�omit_default_directivescs6t|�D](}t||j�durt��|j|���qdS�N)�	dc_fields�getattrr�super�__setattr__�type)�selfZfield��	__class__rr�
__post_init__�szManifestControl.__post_init__)rrrrW�list�str�__annotations__rX�boolrb�
__classcell__rrr`rrV�s
rVc@s6eZdZd
dd�Zdd�Zdd�Zd	d
�Zdd�ZdS)�CollectionSignatureErrorNFcCs"||_||_||_||_d|_dSrY)�reasons�stdout�rc�ignore�_reason_wrapper)r_rirjrkrlrrr�__init__�s
z!CollectionSignatureError.__init__cCsd|�d|j�d|j��S)NzUnexpected error for 'z<': GnuPG signature verification failed with the return code z and output )rkrj�r_�collection_namerrr�_report_unexpected�s���z+CollectionSignatureError._report_unexpectedcCs d|�d|j�d�}||��S)N�#Signature verification failed for 'z' (return code z):)rk�_format_reasons)r_rp�headerrrr�_report_expected�sz)CollectionSignatureError._report_expectedcs<�jdurtjddd��_�fdd��jD�}dd�|�S)Nz    * z      )�initial_indent�subsequent_indentcsg|]}d��j�|���qS)�
)�joinrm�wrap)�.0�reason�r_rr�
<listcomp>�s�z<CollectionSignatureError._format_reasons.<locals>.<listcomp>rx)rm�textwrapZTextWrapperriry)r_Zwrapped_reasonsrr}rrs�s
�
�z(CollectionSignatureError._format_reasonscCs|jr|�|�S|�|�SrY)rirurqrorrr�report�s
zCollectionSignatureError.report)NNNF)rrrrnrqrursr�rrrrrh�s

rhc@seZdZdd�ZdS)�CollectionVerifyResultcCs||_d|_dS)NT)rp�successrorrrrn�szCollectionVerifyResult.__init__N)rrrrnrrrrr��sr�c
Cs t|j�}t|jdd�}t�dj|d��t�djt|j�d��g}|du}t�t	|�}t�t
|�}|s�|j|jkr�dj|j|j|jd	�}	t�|	�d
|_|St
j�t|dd�t�}
t|j�}|r�|jdur�dd�|jd
D�|}n|�s|j�rt|j�|}|jdu}|�s&|�r&t�d�n<|�rbt|j|
||j|j|j��sRd
|_|St�d|���|�rr|t�}
nt|�r�|j�r�|t�}
n\|j�r�|jn|j|�}t�djt|�d��t�t|�}t�t|�}|t�}
t |t|
|�t�dj|
d��|t�}|d}|d}|d|d}t ||||�||�}t!�}t
j�|d�t
j�|d�h}|dD]�}|d}|ddk�r�|�"t
j�|t|dd���|d|d}t ||||�|ddk�r`|�"t
j�|t|dd����q`t
�#|�D]�\}}}|D]N}t
j�||�}t|t$|�dd�dd�}||v�r�|�%t&|ddd ���q�|D]N}t
j�||�}t|t$|�dd�dd�}||v�rN|�%t&|d!d"d ���qN�q�|�r�d
|_t�d#jt|j�d$��|D],}t�d%|j'�t�(d&|j)|j*f��q�n"|�rd'nd(}t�d)j||d*��|S)+a5Verify integrity of the locally installed collection.

    :param local_collection: Collection being checked.
    :param remote_collection: Upstream collection (optional, if None, only verify local artifact)
    :param artifacts_manager: Artifacts manager.
    :return: a collection verify result object.
    �surrogate_or_strict��errorszVerifying '{coll!s}'.��collz(Installed collection found at '{path!s}'��pathNzX{local_fqcn!s} has the version '{local_ver!s}' but is being compared to '{remote_ver!s}')Z
local_fqcnZ	local_verZ
remote_verFcSsg|]}|d�qS)�	signaturer)r{�inforrrr~��z+verify_local_collection.<locals>.<listcomp>�
signaturesz�The GnuPG keyring used for collection signature verification was not configured but signatures were provided by the Galaxy server. Configure a keyring for ansible-galaxy to verify the origin of the collection. Skipping signature verification.z>GnuPG signature verification succeeded, verifying contents of z&Remote collection cached as '{path!s}'z#MANIFEST.json hash: {manifest_hash})�
manifest_hashrrz	chksum_%sr�
MANIFEST.json�
FILES.jsonr.r�file�dirrPzthe file does not existzthe file existsrRzthe directory does not existzthe directory existszECollection {fqcn!s} contains modified content in the following files:��fqcnz    %sz    Expected: %s
    Found: %sz+are internally consistent with its manifestzmatch the remote collectionz=Successfully verified that checksums for '{coll!s}' {what!s}.)r��what)+r�r�rF�src�displayrrH�	functools�partialr3�_get_file_hash�verr��osr�ry�MANIFEST_FILENAMErcr�Zsource_info�keyring�warning�verify_file_signatures�#required_successful_signature_count�ignore_signature_errors�vvvv�is_concrete_artifact�get_artifact_path�get_galaxy_artifact_path�vvv�_get_json_from_tar_file�_get_tar_file_hash�_verify_file_hash�set�add�walk�len�appendrQrS�vrTrU)�local_collection�remote_collection�artifacts_manager�result�b_collection_pathZmodified_contentZverify_local_onlyZget_json_from_validation_sourceZget_hash_from_validation_source�err�
manifest_filer�Zkeyring_configuredr�Zb_temp_tar_path�manifestZfile_manifest_dataZfile_manifest_filename�
expected_hash�
file_manifestZcollection_dirsZcollection_filesZ
manifest_datar�root�dirsr.�	full_pathr�Zcontent_changer�rrr�verify_local_collection�s�	
����


��

�
�����
�
�����r�cCs\d}g}t�t|���}|dp"d}	|d}
|d}|durDt|�}|D]�}t|dd�}zt||||�WnFty�}
z.|
jr�WYd}
~
qH|�	|
�
|��WYd}
~
qHd}
~
00|d7}|
r�qH||krHq�qH|	r�|s�d}t�d	|�d
��nN|
�r|}|�s<t�d	|�d��n(|�p"||k}|�s<t�d	|�d��|�sX|D]}t�|��qF|S)
Nr�strictF�all�countr�r�rPrrz': no successful signaturesz': some signatures failedz,': fewer successful signatures than required)
�re�match�SIGNATURE_COUNT_RE�	groupdict�intrH�verify_file_signaturerhrlr�r�r�r�)r�r�Zdetached_signaturesr�Zrequired_successful_countr�Z
successfulZerror_messagesZsignature_count_requirementsr�Zrequire_allZ
require_countr��errorZverified�msgrrrr�ysF&r�cCs�t|||t�\}}|r�t|�}zt|�}Wnty<Ynz0g}d}	t|g|�D]B}tt���tt�	���
|j�}
|
|vr�|	d7}	|�|�
��qRt|�|	k}tt|�|||d��|r�t||d��dS)zURun the gpg command and parse any errors. Raises CollectionSignatureError on failure.rrP)rirjrkrl)rjrkN)r7r�r8�next�
StopIterationrrcr:�keys�values�indexrar�Zget_gpg_error_descriptionr�rhr�)r�Zdetached_signaturer�r�Z
gpg_resultZgpg_verification_rcr�r�riZignored_reasonsZstatus_coderlrrrr��s& r�c
Cst|dd�}zt|�}Wn6tyN}zttt|��|�WYd}~n
d}~00tfi|��}t||d|d|d|d�}dj|d|d|d	d
�}t	j
�t|�t|dd��}	t	j
�|	�r�t	j
�
|	�r�tdt|	���n|s�tdt|	���t||	||�}
|
S)
a�Creates the Ansible collection artifact in a .tar.gz file.

    :param u_collection_path: The path to the collection to build. This should be the directory that contains the
        galaxy.yml file.
    :param u_output_path: The path to create the collection build artifact. This should be a directory.
    :param force: Whether to overwrite an existing collection build artifact or fail.
    :return: The path to the collection build artifact.
    r�r�Nr r�build_ignorer�z{ns!s}-{name!s}-{ver!s}.tar.gzr!)r�nsr�zQThe output collection artifact '%s' already exists, but is a directory - abortingzWThe file '%s' already exists. You can use --force to re-create the collection artifact.)rFr4�LookupErrorrEr/rG�_build_manifest�_build_files_manifestrr�r�ry�exists�isdir�_build_collection_tar)�u_collection_pathZ
u_output_path�forcer��collection_metaZ
lookup_err�collection_manifestr�Zartifact_tarball_file_name�b_collection_output�collection_outputrrr�build_collection�sB
(��
���r�cCs�td��.tt|�|d|||dddd�	}Wd�n1s<0Yt|dd�}g}tdj|d����||����D]�\}	}
|
jr�t�d	jt	|
�d
��qvt�djt	|
�t	|�d��|
j
r�|jn|j|
�}t
j�|t
j�|��}|
j�rttt	|dd�t	|dd�d
d�dd�}nt�t|�t|��t�dj|
d
��|�tt
j�|��|
jd��qvt
j�|d�}
t|
dd�}t�djt	|
�d��ttd|i�dd�}t|dd��}|�|�Wd�n1�s�0YWd�n1�s�0YdS)a�Download Ansible collections as their tarball from a Galaxy server to the path specified and creates a requirements
    file of the downloaded requirements to be used for an install.

    :param collections: The collections to download, should be a list of tuples with (name, requirement, Galaxy Server).
    :param output_path: The path to download the collections to.
    :param apis: A list of GalaxyAPIs to query when search for a collection.
    :param validate_certs: Whether to validate the certificate if downloading a tarball from a non-Galaxy host.
    :param no_deps: Ignore any collection dependencies and only download the base requirements.
    :param allow_pre_release: Do not ignore pre-release versions when selecting the latest.
    zProcess download dependency mapNF��galaxy_apis�preferred_candidates�concrete_artifacts_manager�no_deps�allow_pre_release�upgrade�include_signatures�offliner�r�z2Starting collection download process to '{path!s}'r�z{coll!s} is not downloadabler�z/Downloading collection '{coll!s}' to '{path!s}'�r�r�T)r�z1Collection '{coll!s}' was downloaded successfully)rr!zrequirements.ymlzEWriting requirements.yml file of downloaded collections to '{path!s}'�collections�wb��mode)�_display_progress�_resolve_depenency_mapr�rFr�copy�items�
is_virtualr�rHr�r�r�r�r�ry�basename�is_dirr��shutilrGr�r�rJ�open�write)r��output_path�apisr�r�r�Zdep_mapZ
b_output_pathZrequirementsr��concrete_coll_pin�
b_src_pathZb_dest_pathZrequirements_pathZb_requirements_pathZ
yaml_bytesZreq_fdrrr�download_collections�s�
�$
��������
�

��	���
���
�r�cCs�|�|�}|r�d}t|�d��D]}|r |}q2q |sBtd|��tdj|d���|�||�Wd�n1st0Yt�d|j|j	f�nt�d|j|j	|f�dS)ayPublish an Ansible collection tarball into an Ansible Galaxy server.

    :param collection_path: The path to the collection tarball to publish.
    :param api: A GalaxyAPI to publish the collection to.
    :param wait: Whether to wait until the import process is complete.
    :param timeout: The time in seconds to wait for the import process to finish, 0 is indefinite.
    N�/zoPublishing the collection did not return valid task info. Cannot wait for task status. Returned task info: '%s'zRCollection has been published to the Galaxy server {api.name!s} {api.api_server!s})�apizRCollection has been successfully published and imported to the Galaxy server %s %sz�Collection has been pushed to the Galaxy server %s %s, not waiting until import has completed due to --no-wait being set. Import task results can be found at %s)
�publish_collection�reversed�splitr/r�rZwait_import_taskr�rZ
api_server)�collection_pathr��wait�timeoutZ
import_uriZtask_idZpath_segmentrrrr�ds*
��*
��r�csdd�t|��D��tt��fdd�|D���}dd�|D��||sH|rNt�n�fdd�|D�8}|sx|sxt�d�dS�fd	d��D�}
|r�gn
|r�|
n�}d
d�|D�}td��,t|||�||||
|d�	}Wd�n1s�0Y�jdu}td
���|��D]�\}}|j	�r6t�
djt|�d���q||v�rZt�djt|�d���q|
�sx|j
�rx|�sxt�d�|jdk�r�|��}zt||��WnLt�y�}z2|�r�t�djt|�t|�d��n�WYd}~n
d}~00�qWd�n1�s0YdS)a�Install Ansible collections to the path specified.

    :param collections: The collections to install.
    :param output_path: The path to install the collections to.
    :param apis: A list of GalaxyAPIs to query when searching for a collection.
    :param validate_certs: Whether to validate the certificates if downloading a tarball.
    :param ignore_errors: Whether to ignore any errors when installing the collection.
    :param no_deps: Ignore any collection dependencies and only install the base requirements.
    :param force: Re-install a collection if it has already been installed.
    :param force_deps: Re-install a collection as well as its dependencies if they have already been installed.
    cSs$h|]}t|j|j|j|jd��qSrY)r
r�r�r�r^�r{r�rrr�	<setcomp>�s�z&install_collections.<locals>.<setcomp>c3s6|].}|jr(�fdd���|���D�n|fVqdS)c3s|]}t�|��VqdSrY)r
�
from_dir_path)r{Zsub_coll�r�rr�	<genexpr>�s�z0install_collections.<locals>.<genexpr>.<genexpr>N)Z
is_subdirsZ"get_direct_collection_dependenciesr�)r{Zinstall_reqrrrr�s
����z&install_collections.<locals>.<genexpr>cSsh|]
}|j�qSrr�)r{�reqrrrr�r�cs4h|],}�D]"}|j|jkrt|j|j�r|�qqSr)r�rCr�)r{rZexs)�existing_collectionsrrr�s�zxNothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.Ncsh|]}|j�vr|�qSrr�r)�requested_requirements_namesrrr�s
�cSs$h|]}t|j|j|j|jd��qSrY)rAr�r�r�r^rrrrr�s�zProcess install dependency mapr�z#Starting collection install processzEncountered {coll!s}, skipping.r�z*'{coll!s}' is already installed, skipping.aThe GnuPG keyring used for collection signature verification was not configured but signatures were provided by the Galaxy server to verify authenticity. Configure a keyring for ansible-galaxy to use or disable signature verification. Skipping signature verification.�galaxyzeFailed to install collection {coll!s} but skipping due to --ignore-errors being set. Error: {error!s})r�r�)�find_existing_collectionsr�r�
from_iterabler�r�r�r�r�r�r�rrHr�r�r^Zwith_signatures_repopulated�installr/)r�r�r��
ignore_errorsr�r�Z
force_depsr�r�r�Zdisable_gpg_verifyr�Zunsatisfied_requirementsZ"existing_non_requested_collectionsZpreferred_requirementsZpreferred_collectionsZdependency_mapZkeyring_existsr�r�r�r)r�r	r
r�install_collections�s��
����
���
�$

��
���	��	rcCs.|�d�\}}}t�|�r|Std|��dS)z�Validates the collection name as an input from the user or a requirements file fit the requirements.

    :param name: The input name with optional range specifier split by ':'.
    :return: The input value, required for argparse validation.
    �:z�Invalid collection name '%s', name must be in the format <namespace>.<collection>. 
Please make sure namespace and collection name contains characters from [a-zA-Z0-9_] only.N)�	partitionrKZis_valid_collection_namer/)r�
collection�dummyrrr�validate_collection_names
�rcCs&tj�|�ddkr"tj�|d�S|S)z�Ensure a given path ends with 'ansible_collections'

    :param collection_path: The path that should end in 'ansible_collections'
    :return: collection_path ending in 'ansible_collections' if it does not already.
    rPZansible_collections)r�r�r�ry)rrrr�validate_collection_path'srcCs2g}t||�}t���|D�]�}�z�|jr@tdj|jd�d��d|j}	|D]�}
ttj	�
|
|j|j�dd�}tj	�
|�s|qNt|�s�d|j}	qNt�||�}dd	�|jp�gD�}
t|j|j|j|jt|
�d
�}q�qNt|	d��|r�d}n�|�|�}|�dd	�|j�pgD��t|j|jd
k�r&|jn|jddt|��}z |jdu�sL|�sV|�|�WnPt�y�}z6dj|d�}|j|k�r�tdj|d����WYd}~n
d}~00t|||�}|�|�Wqt�y
}z.|�r�t�dj|t|�d��n�WYd}~qd}~00qWd�n1�s$0Y|S)aMVerify the integrity of locally installed collections.

    :param collections: The collections to check.
    :param search_paths: Locations for the local collection lookup.
    :param apis: A list of GalaxyAPIs to query when searching for a collection.
    :param ignore_errors: Whether to ignore any errors when verifying the collection.
    :param local_verify_only: When True, skip downloads and only verify local manifests.
    :param artifacts_manager: Artifacts manager.
    :return: list of CollectionVerifyResult objects describing the results of each collection verification
    zM'{coll_type!s}' type is not supported. The format namespace.name is expected.)Z	coll_type)�messagez>Collection %s is not installed in any of the collection paths.r�r�z�Collection %s does not have a MANIFEST.json. A MANIFEST.json is expected if the collection has been built and installed via ansible-galaxycSsg|]}t|t��qSr�r9r��r{�sourcerrrr~ms�z&verify_collections.<locals>.<listcomp>)r�NcSsg|]}t|t��qSrrrrrrr~�s��*rz4Failed to find collection {coll.fqcn!s}:{coll.ver!s}r�zHFailed to find remote collection '{coll!s}' on any of the galaxy serverszdFailed to verify collection '{coll!s}' but skipping due to --ignore-errors being set. Error: {err!s})r�r�)r6r�r�r/rr^r�rFr�r�ryr rr�rBrArZsignature_sourcesr�r��	frozensetZget_signatures�extendr�Zget_collection_version_metadatarr�r�r�r�rH)r�Zsearch_pathsr�rZlocal_verify_onlyr��resultsZ	api_proxyrZdefault_err�search_pathZ
b_search_pathr�Zsupplemental_signaturesr�r��eZexpected_error_msgr�r�rrr�verify_collections4s�


��	
�������



��	�������:r!c	cs<tjttjdd�d�}z|VWt�|�nt�|�0dS)Nr�r�)r�)�tempfileZmkdtemprF�CZDEFAULT_LOCAL_TMPr��rmtree)�b_temp_pathrrr�_tempdir�sr&ccs�tj}|durtj��n|}|dur.t�|�|s<dVdSdd�}Gdd�dt�}t}z|z^t��}||�at	j
|||fd�}d|_|��zdVWd|_
|��nd|_
|��0Wnty��Yn0W|an|a0dS)Nc	Ss�|�d�t��}dD]�}|j|ddd�t�d�z|jddd�\}}}WntjyfYq�Yq60t	||�}||i|��q6t	|dd�r|�d	�dSqqdS)
Nz(Starting display_progress display threadz|/-\�F)�newlineg�������?)�blockr�finishz7Received end signal for display_progress display thread)
�debug�	threading�current_threadr��time�sleep�get�queueZEmptyr[)�
display_queueZactual_display�t�c�method�args�kwargs�funcrrr�progress�s




z#_display_progress.<locals>.progressc@seZdZdd�Zdd�ZdS)z(_display_progress.<locals>.DisplayThreadcSs
||_dSrY)r2)r_r2rrrrn�sz1_display_progress.<locals>.DisplayThread.__init__cs��fdd�}|S)Ncs�j��||f�dSrY)r2Zput)r6r7��attrr_rr�call_display�szJ_display_progress.<locals>.DisplayThread.__getattr__.<locals>.call_displayr)r_r;r<rr:r�__getattr__�sz4_display_progress.<locals>.DisplayThread.__getattr__N)rrrrnr=rrrr�
DisplayThread�sr>)�targetr6T)r#ZGALAXY_DISPLAY_PROGRESS�sysrj�isattyr��objectr1ZQueuer,�Thread�daemon�startr*ry�	Exception)r�Zconfig_displayZ
display_wheelr9r>Zold_displayr2r3rrrr��s2

�
r�cCs�ttj�t|�|�dd�}tj�|�s,d}n4t|dd��}t|�}Wd�n1sV0Y||kr||�t	|||d��dS)Nr�r��rbr�rR)
rFr�r�ryrH�isfiler�r1r�rQ)�b_pathrSr�Zerror_queueZb_file_path�actual_hashZfile_objectrrrr�s&r�cCsddddtd�gtd�S)N�.r�rr-��MANIFEST_FORMATrrrr�_make_manifests��	�rNr	c
Cs&d|d|d|r|ndd|��|dtiS)NrrrZchksum_rrL)rrr�chksumrrr�_make_entry"s
�rPcCs8|r|turtd��|tur*t||||�St||||�S)Nz4"build_ignore" and "manifest" are mutually exclusive)rOr/�_build_files_manifest_distlib�_build_files_manifest_walk)r�r r�ignore_patterns�manifest_controlrrrr�,s�r�cCs~tstd��|duri}ztfi|��}Wn2ty\}ztd|����WYd}~n
d}~00t|j�s|td|jjj����t|j	t
�s�td|j	jj����|j	r�|js�td��g}|j	r�|�|j�n�|�gd��tdd�t
�D��}t|�D].}|d	v�rq�q�|tjvr�|�d
|�d��q�|�dd
g�|�|j�|�d|�d|�d�ddg�t�d�t�t�d�|�d��t|dd�}	t|	�}
|D]|}z|
�|�Wnft�y�}ztd|����WYd}~n<d}~0t�y}ztd|����WYd}~n
d}~00�q�t�}
|
jdd�D]T}tj�||	�}tj� |��rPt!|d�}nt!|ddt"|t#d�d �}|
d!�|��q$|
S)"Nz7Use of "manifest" requires the python "distlib" libraryzInvalid "manifest" provided: z+"manifest.directives" must be a list, got: zE"manifest.omit_default_directives" is expected to be a boolean, got: z�"manifest.omit_default_directives" was set to True, but no directives were defined in "manifest.directives". This would produce an empty collection artifact.)zinclude meta/*.ymlz(include *.txt *.md *.rst COPYING LICENSEzrecursive-include tests **zArecursive-include docs **.rst **.yml **.yaml **.json **.j2 **.txtz4recursive-include roles **.yml **.yaml **.json **.j2z2recursive-include playbooks **.yml **.yaml **.jsonz+recursive-include changelogs **.yml **.yamlz!recursive-include plugins */**.pycss"|]\}}|j�d�dVqdS)rK���N)�packager�)r{�d�lrrrrhr�z0_build_files_manifest_distlib.<locals>.<genexpr>)�modulesZmodule_utilszrecursive-include plugins/z **.yml **.yamlz7recursive-include plugins/modules **.ps1 **.yml **.yamlz;recursive-include plugins/module_utils **.ps1 **.psm1 **.csz8exclude galaxy.yml galaxy.yaml MANIFEST.json FILES.json �-z	-*.tar.gzz!recursive-exclude tests/output **zglobal-exclude /.* /__pycache__zManifest Directives:rxz    r�r�zInvalid manifest directive: z-Unknown error processing manifest directive: T)Zwantdirsr�r�r	�Z	hash_func�rrOr.)$�HAS_DISTLIBr/rV�	TypeErrorrIrWrar�
isinstancerXrfrr�rD�sortedr#ZDOCUMENTABLE_PLUGINSr�r�r�r�indentryrHrZprocess_directiverrFrNr�r��relpathr�rPrMr	)r�r rrTZcontrol�exrWZpluginsZpluginr��mZ	directiver r�Zabs_path�rel_pathZmanifest_entryrrrrQ<s�$
���


���
"(
�rQc
sfddddddddtd	�||��g	��d
d�|D�7�tgd���t������fd
d���||��S)Nr�r�s
galaxy.ymlsgalaxy.yaml�.gits*.pycs*.retrystests/outputz{0}-{1}-*.tar.gzcSsg|]}t|��qSr)rF�r{�prrrr~�r�z._build_files_manifest_walk.<locals>.<listcomp>)sCVSs.bzrs.hgrfs.svns__pycache__s.toxcs^t�|�D�]L�tj�|��}||kr*dn|t|�dd�}tj�|���t�dd�}tj�|��r
t�fdd��D��s�t�fdd��D��r�t�	dt|��q
tj�
|�r�tj�|�}t||�s�t�
d	t|��q
�d
�t|d��tj�
|��sX�||�q
t�fdd��D���r6t�	dt|��q
�d
�t|d
dt|td�d��q
dS)Nr�rPr�r�c3s|]}�|kVqdSrYr)r{rI)�b_itemrrr�r�z<_build_files_manifest_walk.<locals>._walk.<locals>.<genexpr>c3s|]}t��|�VqdSrY��fnmatch�r{Z	b_pattern��
b_rel_pathrrr�r�z"Skipping '%s' for collection buildzLSkipping '%s' as it is a symbolic link to a directory outside the collectionr.r�c3s|]}t��|�VqdSrYrjrlrmrrr�r�r�r	r[r\)r��listdirr�ryr�rHr��anyr�r��islink�realpath�_is_child_pathr�r�rPrMr	)rIZb_top_level_dirZ
b_abs_pathZb_rel_base_dirre�
b_link_target��_walkZ
b_ignore_dirsZb_ignore_patternsr�)rirnrrv�s@ �
�
��z)_build_files_manifest_walk.<locals>._walk)rFrrrN)r�r rrSrrurrR�s �)
rRc
KsB||||||||
d|pd||	|
||d�ddddtd�td�}|S)Nr&)r rr!r"r#r$r%r&r'r(r)r*r+r,�
FILES.jsonr�r	rrrL)r rr!r"r#r$r%r'r(r)r*r+r,r7r�rrrr��s0���r�c
Cs8ttj|dd�dd�}t|td�|dd<ttj|dd�dd�}t����}tj�|tj�	|��}t
j|dd	���D}t|fd
|ffD]F\}	}
t
|
�}t
�|	�}t|
�|_tt���|_d|_|j||d�q�|d
D]�}
|
ddkr�q�t|
ddd�}tj�|t|dd��}dd�}tj�|��r�tj�|�}t||��r�tjj|tj�|�d�}t
�|�}t
j|_t|dd�|_||�}|j|d�q�|jttj�|��|d|d�q�Wd�n1�s�0Yt �!t|�t|��d|dd|ddf}t"|�}t#�#d||f�|Wd�S1�s*0YdS)z:Build a tar.gz collection artifact from the manifest data.T�rar�r�r[rrzw:gzr�rw�)�tarinfoZfileobjr.rrKcSsJ|jtjkr.|jtj@}|s$|��r(dnd|_d|_|_d|_	|_
|S)N��ryr�)r^�tarfile�SYMTYPEr��stat�S_IXUSRr��uid�gid�uname�gname)rz�existing_is_execrrr�
reset_stat!sz)_build_collection_tar.<locals>.reset_stat)rE)rzF)Zarcname�	recursive�filterN�%s.%srr zCreated collection for %s at %s)$rF�json�dumpsrNr	r&r�r�ryr�r}r�r�r
ZTarInfor��sizer�r.�mtimer�ZaddfilerGrqrrrsrb�dirnamer~r^�linknamer�r�r�rHr�)r�Z
b_tar_pathr�r��files_manifest_json�collection_manifest_jsonr%Zb_tar_filepathZtar_filer�b�b_ioZtar_info�	file_inforSr�r�rtrnrpZtar_pathrrrr�sT


	
�(
�r�c
Cs�tj|dd�ttj|dd�dd�}t|td�|dd	<ttj|dd�dd�}t|fd
|ffD]�\}}tj�	|t|dd��}t
|d��D}	t|��}
t�
|
|	�Wd�n1s�0YWd�n1s�0Yt�|d
�q^g}t|ddd�d�D]�}|ddk�r�qtj�	|t|ddd��}
tj�	|t|ddd��}t�|
�jtj@}|�rfdnd
}tj�|
��r�d}|�|
�t�||�nt�|
|�t�||��qt|�}|S)z|Build a collection directory from the manifest data.

    This should follow the same pattern as _build_collection_tar.
    r{r�Trxr�r�r[rrrwr�Nryr.cSs|dS)Nrr)�xrrr�<lambda>[r�z'_build_collection_dir.<locals>.<lambda>)�keyrrK)r��makedirsrFr�r�rNr	r�r�ryr�r
r��copyfileobj�chmodr`r�st_moder�r�r��mkdir�copyfilerH)r�r�r�r�r�r�rr�rIZfile_objr�Zbase_directoriesr�Zsrc_fileZ	dest_filer�r�r�rrr�_build_collection_dirGs2H
r�c	cs�t|dd�}t�|�D]�}tj�||�}tj�|�r6qt�|�D]�}tj�||�}tj�|�s`q@zt�||�}Wn2t	y�}zt
t|�|�WYd}~n
d}~00t�
djt|�t|j�d��|Vq@qdS)z�Locate all collections under a given path.

    :param path: Collection dirs layout search path.
    :param artifacts_manager: Artifacts manager.
    r�r�Nz1Found installed collection {coll!s} at '{path!s}'r�)rFr�ror�ryrHr�rAZfrom_dir_path_as_unknown�
ValueErrorrEr/r�r�rrHr�)	r�r�rIZb_namespace�b_namespace_pathZb_collectionr�rZval_errrrrrqs&$��rcCs�|jr|jn|j|�}tj�||j|j�}t|dd�}t	�	dj
t|�|d��tj�|�rdt
�|�|jrzt||||�n<t|||j|j|j|j|j�|jr�t|jt�r�t|||�t	�	dj
t|�d��dS)z�Install a collection under a given path.

    :param collection: Collection to be installed.
    :param path: Collection dirs layout path.
    :param artifacts_manager: Artifacts manager.
    r�r�z#Installing '{coll!s}' to '{path!s}'r�z#{coll!s} was installed successfullyr�N)r�r�r�r�r�ryr rrFr�rrHr�r�r$r��install_src�install_artifactZ_b_working_directoryr�r�r�r�Zis_online_index_pointerr_r�r0�write_source_metadata)rr�r�Zb_artifact_pathrr�rrrr�sF	���
�	���rcCs�|�|�}tt|�dd�}|�|�}tj�|�d}tj�|�rJt�	|�zTtj
|dd�t|dd��}|�|�Wd�n1s�0Yt�
|d�Wn*ty�tj�|�r�t�	|��Yn0dS)Nr�r�rr{r�zw+bry)Zget_galaxy_artifact_source_inforFrJZconstruct_galaxy_info_pathr�r�r�r�r�r$r�r�r�r�rFr�)rr�r�Zsource_dataZb_yaml_source_dataZb_info_destZ
b_info_dir�fdrrrr��s


(
r�cCsdd}t|dd��tjj�}d|d|df}t||||||�sPtd|�d���t�d	|���dS)
NFr�r�r�������zNot installing z- because GnuPG signature verification failed.z+GnuPG signature verification succeeded for )	rHr�r�r��sepr�r/r�r�)r�r�r��required_signature_countr�Z
failed_verifyZcoll_path_partsrprrr�verify_artifact_manifest�sr�c	Cs~�z4tj|dd���}dd�|��D�|_t|t||�|durftj�t	|dd�t�}t
|||||�|�d�}	t||	��*\}
}t
�t	|��dd��}Wd�n1s�0Yt|d||�|d	D]H}
|
d
}|dkr�q�|
dd
k�rt|||||
dd�q�t|||�q�Wd�n1�s*0YWnBt�yxt�|�tj�|�}t�|��srt�|��Yn0dS)a.Install a collection from tarball under a given path.

    :param b_coll_targz_path: Collection tarball to be installed.
    :param b_collection_path: Collection dirs layout path.
    :param b_temp_path: Temporary dir path.
    :param signatures: frozenset of signatures to verify the MANIFEST.json
    :param keyring: The keyring used during GPG verification
    :param required_signature_count: The number of signatures that must successfully verify the collection
    :param ignore_signature_errors: GPG errors to ignore during signature verification
    �rr�cSsi|]}|j�tjj�|�qSr)r�removesuffixr�r�r�)r{rdrrr�
<dictcomp>�sz$install_artifact.<locals>.<dictcomp>Nr�r�rwr.rrKrr�r)r�)r}r�Z
getmembers�_ansible_normalized_cache�_extract_tar_filer�r�r�ryrHr��	getmemberr5r��loads�read�_extract_tar_dirrFr�r$r�ro�rmdir)Zb_coll_targz_pathr�r%r�r�r�r��collection_tarr�Zfiles_member_objrZ	files_objr.r��	file_namer�rrrr��s8�
4
�2

r�cCsv|�|�}d|vr"g|d<t|d<tfi|��}t||d|d|d|d�}t||||�}t�dj||d��dS)a�Install the collection from source control into given dir.

    Generates the Ansible collection artifact data from a galaxy.yml and
    installs the artifact to a directory.
    This should follow the same pattern as build_collection, but instead
    of creating an artifact, install it.

    :param collection: Collection to be installed.
    :param b_collection_path: Collection dirs layout path.
    :param b_collection_output_path: The installation directory for the \
                                     collection artifact.
    :param artifacts_manager: Artifacts manager.

    :raises AnsibleError: If no collection metadata found.
    r�r�r rz+Created collection for {coll!s} at {path!s}r�N)Zget_direct_collection_metarOr�r�r�r�r)rr�Zb_collection_output_pathr�r�r�r�Zcollection_output_pathrrrr�s(
����r�c
Cst|dd��tjj�}z|j|}WntyBtd|��Yn0tj�|t	|dd��}tj�
|�}ztj|dd�Wn2ty�}z|j
t
jkr��WYd}~n
d}~00|jtjkr�t	|jdd�}t|||d�s�tdt|�|f��t�||�ntj�|��st�|d�dS)	z- Extracts a directory from a collection tar. r�r�z&Unable to extract '%s' from collectionr{r�N��	link_name�]Cannot extract symlink '%s' in collection: path points to location outside of collection '%s')rGr�r�r�r�r��KeyErrorr/ryrFr�r��OSError�errnoZEEXISTr^r}r~r�rs�symlinkr�r�)�tarr��b_dest�
tar_memberZ
b_dir_path�
b_parent_pathr �b_link_pathrrrr�Cs*
�r�c

Cs�t||����\}}|jtjkr(t|�}n8tj|dd��}t||�}Wd�n1sV0Y|r�||kr�tdt|dd�t|j	�f��t
j�t
j�
|t|dd���}	t
j�|	�}
t|
|�s�tdt|dd���t
j�|
�s�t
j|
dd	�|jtjk�r:t|jdd�}t|||	d
��s,tdt|�|f��t
�||	�nTt�t|j	dd�|	�|�t|dd��}d}t�|j�tj@�r�|d
O}t
�|	|�Wd�n1�s�0YdS)z( Extracts a file from a collection tar. F)r��deleteNz4Checksum mismatch for '%s' inside collection at '%s'r�r�zSCannot extract tar entry '%s' as it will be placed outside the collection directoryr{r�r�r�ry�I)�_get_tar_file_memberr^r}r~r1r"ZNamedTemporaryFiler/rGrr�r��abspathryrFr�rsr�r�r�r�r��mover�r�S_IMODEr�r�r�)
r�rSr�r%r�r��tar_objrJZtmpfile_objZb_dest_filepathZb_parent_dirr�Znew_moderrrr�bs<
(�

�
�r�cCsNt|dd�}z|�|�}Wn(tyBtdt|j�|f��Yn0t||�S)Nr�r�z?Collection tar at '%s' does not contain the expected file '%s'.)rGr�r�r/rr5)r�rSZ
n_filename�memberrrrr��s�r�c	Cs�d}tj|dd��h}t||��>\}}d}|�|�}|rN|t|�7}|�|�}q2Wd�n1sb0YWd�n1s�0Yt�|�S)Nr|r�r�i)r}r�r�r�rHr�r�)rIrSZ
file_contentsr�rr��bufsize�datarrrr��s
Hr�c	Csvtj|dd��T}t||��*\}}t|�Wd�Wd�S1sJ0YWd�n1sh0YdS)Nr�r�)r}r�r�r1)rIrSr�rr�rrrr��sr�cCsLtj�|t|dd��}t|d��}t|�Wd�S1s>0YdS)Nr�r�rG)r�r�ryrFr�r1)rIrS�filepath�fprrrr��sr�cCspt|dd�}|rFtj�|�sFtj�t|dd��}tj�tj�||��}t|dd�}||kpn|�|ttjj��S)z> Checks that path is a path within the parent_path specified. r�r�)	rFr�r��isabsr�r�ry�
startswithr�)r��parent_pathr�rIZ
b_link_dirr�rrrrs�srsc	sttstd��tstd��d}	z�ztd�}
Wnty<Yn 0t�fdd�|
jpRgD�d�}	W|	dur�ttkrzt	ks�ntdt	j
�dtj
����n$|	j�tj
�s�td	|	j
�|	j����n`|	dur�ttkr�t	ks�ntdt	j
�dtj
����n&|	j�tj
��std	|	j
�|	j����0t|||||||||d
�	}z|j|dd�jWSt�y�}z>d
d�|jD�}
ttd|
��}ttd�|��|��WYd}~n�d}~0t�y<}z�dd�|j��D�}dj|j|�s�dndjd�|�d�d�g}|j��D]}	|�dj|	d���q�ttd�|��|��WYd}~n<d}~0t�yn}ztt|��|�WYd}~n
d}~00dS)z#Return the resolved dependency map.zHFailed to import resolvelib, check that a supported version is installedzGFailed to import packaging, check that a supported version is installedNzansible-corec3s$|]}t|��jdkr�VqdS)Z
resolvelibN)rr)r{r��Zrrrrr�r�z)_resolve_depenency_map.<locals>.<genexpr>z#ansible-galaxy requires resolvelib<z,>=zansible-galaxy requires )	r�r�Zuser_requirementsr�Z	with_depsZwith_pre_releasesr�r�r�i��)Z
max_roundscss6|].}dj|j|jdurdndj|jd�d�VqdS)z+* {req.fqcn!s}:{req.ver!s} ({dep_origin!s})N�direct request�dependency of {parent!s}��parent�rZ
dep_origin)rZrequirementr�)r{Zreq_infrrrr�s����)z_Failed to resolve the requested dependencies map. Could not satisfy the following requirements:rxcSsg|]}|durt|��qSrY)rdrgrrrr~s�z*_resolve_depenency_map.<locals>.<listcomp>z�Failed to resolve the requested dependencies map. Got the candidate {req.fqcn!s}:{req.ver!s} ({dep_origin!s}) which didn't satisfy all of the following requirements:r�r�z, r�r�z* {req.fqcn!s}:{req.ver!s})r) �HAS_RESOLVELIBr/�
HAS_PACKAGINGrrFr�Zrequiresr?r>r@ZvstringZ	specifier�containsrr;�resolve�mappingr<ZcausesrcrrEryr=Z	criterionZiter_parentr�	candidateZiter_requirementr�r�rG)Zrequested_requirementsr�r�r�r�r�r�r�r�rZdistZcollection_dep_resolverZdep_excZconflict_causesZerror_msg_lines�parents�excrr�rr��s� �����
�
�������
��r�)N)r	N)N)N)��__doc__Z
__future__rrrr^Z
__metaclass__r�rkr�r�r�r1r�r�rr@r}r"rr,r.�typingr3r�r�
contextlibrZdataclassesrrrZZhashlibr	�ior
�importlib.metadatar�	itertoolsrZpackaging.requirementsr
r�ImportErrorr�Zdistlib.manifestrZdistlibrr]�
TYPE_CHECKINGZ3ansible.galaxy.collection.concrete_artifact_managerr�LiteralZManifestKeysTypeZFileMetaKeysTypeZCollectionInfoKeysType�Dict�Unionr�rd�ListZManifestValueTypeZCollectionManifestTypeZFileManifestEntryTypeZFilesManifestTypeZansible.constantsZ	constantsr#Zansible.errorsr/Zansible.galaxy.apir0r1r2r3r4r5Z*ansible.galaxy.collection.galaxy_api_proxyr6Zansible.galaxy.collection.gpgr7r8r9r:Z$ansible.galaxy.dependency_resolutionr;Z+ansible.galaxy.dependency_resolution.errorsr<r=Z.ansible.galaxy.dependency_resolution.providersr>r?r@r�Z0ansible.galaxy.dependency_resolution.dataclassesrArBZ/ansible.galaxy.dependency_resolution.versioningrCZansible.plugins.loaderrDZansible.module_utils.sixrEZansible.module_utils._textrFrGrHZ'ansible.module_utils.common.collectionsrIZ ansible.module_utils.common.yamlrJZansible.utils.collection_loaderrKZansible.utils.displayrLZansible.utils.hashingrMrNZansible.utils.sentinelrOr�rMr�rQr�rVrFrhr�r�r�r�r�r�r�rrrr!r&r�r�rNrPr�rQrRr�r�r�rrr�r�r�r�r�r�r�r�r�r�rsr�rrrr�<module>s


����
.$

),2 /j%

C


bC F* 0
8)
-


Zerion Mini Shell 1.0