
    Vh                        d dl mZ d dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d d
lmZ dgZ G d dee      Zy)    )annotationsN)AnsibleParserErrorAnsibleError)	to_native)string_types)NonInheritableFieldAttribute)Base)CollectionSearch)load_list_of_roles)RoleRequirementRoleMetadatac                       e Zd ZdZ edd      Z ede      Z ed      Z ede	      Z
d fd	Zedd	       Zd
 Zd Zd Z xZS )r   zt
    This class wraps the parsing and validation of the optional metadata
    within each Role (meta/main.yml).
    boolF)isadefaultlistdict)r   c                8    || _         t        t        |           y N)_ownersuperr   __init__)selfowner	__class__s     N/home/dcms/DCMS/lib/python3.12/site-packages/ansible/playbook/role/metadata.pyr   zRoleMetadata.__init__-   s    lD*,    c                    t        | t              st        d|j                         z        t	        |      j                  | ||      }|S )zY
        Returns a new RoleMetadata object based on the datastructure passed in.
        z3the 'meta/main.yml' for role %s is not a dictionary)r   )variable_managerloader)
isinstancer   r   get_namer   	load_data)datar   r   r    ms        r   loadzRoleMetadata.load1   sL     $%$%Z]b]k]k]m%mnnu%//GW`f/gr   c                   g }|rt        |t              st        d| j                        |D ]l  }t        |t              sd|v sd|v r|j                  |       -	 t        j                  |      }|j                  d      r|d   |d<   |j                  |       n d}d}| j                  rt        j                  j                  | j                  j                        }| j                  j                   dd xs g }| j                  j"                  }	|	r'|D 
cg c]
  }
|
|	k7  s	|
 }}
|j%                  d|	       d|vr|j                  d       	 t'        || j                  j(                  || j*                  | j,                  |	      S # t        $ r}t        t        |      ||      d}~ww xY wc c}
w # t.        $ r}t        d
| j                  |      d}~ww xY w)z
        This is a helper loading function for the dependencies list,
        which returns a list of RoleInclude objects
        z(Expected role dependencies to be a list.)objrolename)r(   orig_excNr   zansible.legacy)playcurrent_role_pathr   r    collection_search_listz6A malformed list of role dependencies was encountered.)r!   r   r   _dsr   appendr   role_yaml_parsegetr   r   r   ospathdirname
_role_pathcollections_role_collectioninsertr   _play_variable_manager_loaderAssertionError)r   attrdsrolesrole_def
def_parsedexcr-   r.   owner_collectionces               r   _load_dependencieszRoleMetadata._load_dependencies=   s    b$'()SY]YaYabb Yh589KvYaOaLL*Y!0!@!@!JJ!~~f-+5f+=(LL*Y !!%;; "0F0F G &*[[%<%<Q%?%E2"  ${{;;5K)eqTdOd!)e&)e&--a1AB'==&--.>?	y%e$++2C2CWh7;7M7MVZVbVb=SU U- $ Y,Ys^TWXXY *f  	y$%]cgckckvwxx	ys<   ?F
F3$F38F8 	F0F++F08	GGGc                D    t        | j                  | j                        S )N)allow_duplicatesdependencies)r   _allow_duplicates_dependencies)r   s    r   	serializezRoleMetadata.serializeo   s!    !33++
 	
r   c                x    t        | d|j                  dd             t        | d|j                  dg              y )NrI   FrJ   )setattrr2   )r   r$   s     r   deserializezRoleMetadata.deserializeu   s2    ($((3Eu*MNndhh~r&BCr   r   )NN)__name__
__module____qualname____doc__r   rI   r   rJ   galaxy_infor   argument_specsr   staticmethodr&   rG   rM   rP   __classcell__)r   s   @r   r   r   "   sd    
 4N/FDIL.6:K1fdKN- 	 	0yd
Dr   )
__future__r   r3   ansible.errorsr   r   +ansible.module_utils.common.text.convertersr   ansible.module_utils.sixr   ansible.playbook.attributer   ansible.playbook.baser	   !ansible.playbook.collectionsearchr
   ansible.playbook.helpersr   !ansible.playbook.role.requirementr   __all__r    r   r   <module>rd      s@   $ # 	 ; A 1 C & > 7 =
UD4) UDr   