
    VhN%                        d dl mZ d dlZd dlmZ d dlmZmZ d dl	m
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 dlmZ d dlmZ d dl m!Z! dgZ" e!       Z# G d deeee      Z$y)    )annotationsN)	constants)AnsibleErrorAnsibleAssertionError)string_types)AnsibleBaseYAMLObjectAnsibleMapping)NonInheritableFieldAttribute)Base)CollectionSearch)Conditional)Taggable)Templar)AnsibleCollectionRef)_get_collection_role_path)unfrackpath)DisplayRoleDefinitionc                  t     e Zd Z ed      Zd fd	Zedd       Z fdZd Z	d Z
d Zd	 Zd
 ZddZ xZS )r   string)isac                    t         t        |           || _        || _        || _        d | _        d | _        || _        t               | _
        || _        y N)superr   __init___play_variable_manager_loader
_role_path_role_collection_role_basedirdict_role_params_collection_list)selfplayrole_basedirvariable_managerloadercollection_list	__class__s         P/home/dcms/DCMS/lib/python3.12/site-packages/ansible/playbook/role/definition.pyr   zRoleDefinition.__init__.   sO    nd,.
!1 $) F /    c                    t        d      )Nznot implemented)r   )datar(   r)   s      r,   loadzRoleDefinition.load?   s    ,--r-   c                   t        |t              rd|z  }t        |t              s*t        |t              st        |t              s
t               t        |t              rt        t        | #  |      }|| _	        t               }t        |t              r|j                  |_        | j                  |      }| j                  |      \  }}t        |t              r | j                  |      \  }}||z  }|| _        ||d<   || _        |S )Nz%srole)
isinstanceintr"   r   r   r   r   r   preprocess_data_dsr	   ansible_pos_load_role_name_load_role_path_split_role_paramsr#   r   )r%   dsnew_ds	role_name	role_pathnew_role_defrole_paramsr+   s          r,   r5   zRoleDefinition.preprocess_dataC   s     b#B"d#Jr<,HQ[\^`uQv'))b$~t<R@B 
  !b/0!#F
 ((,	!%!5!5i!@I
 b$*.*A*A"*E'\;l"F +D #v $ r-   c                ^   t        |t              r|S |j                  d|j                  d            }|rt        |t              st        d|      | j                  rN| j                  j                  | j                        }t        | j                  |      }|j                  |      }|S )z
        Returns the role name (either the role: or name: field) from
        the role definition, or (when the role definition is a simple
        string), just that string
        r2   namez)role definitions must contain a role nameobjr&   r)   	variables)
r3   r   getr   r   get_varsr   r   r   template)r%   r;   r=   all_varstemplars        r,   r8   zRoleDefinition._load_role_namep   s     b,'IFF6266&>2	
9l CJPRSS !!--66DJJ6GHT\\XFG((3Ir-   c                   | j                   '| j                   j                  | j                        }n
t               }t	        | j
                  |      }|j                  |      }d}| j                  st        j                  |      rt        || j                        }|r|d   | _        |dd S t        j                  j                  | j
                  j                         d      g}t         j"                  r|j%                  t         j"                         | j&                  r|j)                  | j&                         |j)                  | j
                  j                                |D ]]  }|j                  |      }t+        t        j                  j                  ||            }| j
                  j-                  |      sY||fc S  t+        |      }| j
                  j-                  |      r#t        j                  j/                  |      }||fS | j                  xs g |z   }t1        d|dd	j                  |      | j2                  
      )a  
        the 'role', as specified in the ds (or as a bare string), can either
        be a simple name or a full path. If it is a full path, we use the
        basename as the role name, otherwise we take the name as-given and
        append it to the default role path
        NrE   rF      r   rolesz
the role 'z' was not found in :rC   )r   rI   r   r"   r   r   rJ   r$   r   is_valid_fqcrr   r    ospathjoinget_basedirCDEFAULT_ROLES_PATHextendr!   appendr   path_existsbasenamer   r6   )	r%   r=   rK   rL   
role_tuplerole_search_pathsrS   r>   searchess	            r,   r9   zRoleDefinition._load_role_path   s    !!---66DJJ6GHvHB$$Y/	
   $8$F$Fy$Q29d>S>STJ$.qMD!a?" GGLL113X>

 $$Q%9%9: $$T%7%78
 	  !9!9!;< & 	.D##D)D#BGGLLy$ABI||''	2!9--		.  	*	<<##I.((3Iy))))/R3DD)SXXV^M_`fjfnfnoor-   c                    t               }t               }t        | j                        }|j                         D ]  \  }}||vr|||<   |||<    ||fS )z
        Splits any random role params off from the role spec and store
        them in a dictionary of params for parsing later
        )r"   	frozensetfattributesitems)r%   r;   role_defr@   base_attribute_nameskeyvalues          r,   r:   z!RoleDefinition._split_role_params   si     6f()9)9:HHJ 	&LS% ..#(C  !&	& +&&r-   c                6    | j                   j                         S r   )r#   copyr%   s    r,   get_role_paramszRoleDefinition.get_role_params   s      %%''r-   c                    | j                   S r   )r   ri   s    r,   get_role_pathzRoleDefinition.get_role_path   s    r-   c                z    |r.dj                  d | j                  | j                  fD              S | j                  S )N.c              3  &   K   | ]	  }|s|  y wr    ).0xs     r,   	<genexpr>z*RoleDefinition.get_name.<locals>.<genexpr>   s     O!QAOs   )rT   r    r2   )r%   include_role_fqcns     r,   get_namezRoleDefinition.get_name   s3    88O(=(=tyy'IOOOyyr-   )NNNNN)NN)T)__name__
__module____qualname__r
   r2   r   staticmethodr0   r5   r8   r9   r:   rj   rl   ru   __classcell__)r+   s   @r,   r   r   *   sM    'H5D0" . .+Z.BpH'4(r-   )%
__future__r   rR   ansibler   rV   ansible.errorsr   r   ansible.module_utils.sixr   ansible.parsing.yaml.objectsr   r	   ansible.playbook.attributer
   ansible.playbook.baser   !ansible.playbook.collectionsearchr   ansible.playbook.conditionalr   ansible.playbook.taggabler   ansible.templater   ansible.utils.collection_loaderr   2ansible.utils.collection_loader._collection_finderr   ansible.utils.pathr   ansible.utils.displayr   __all__displayr   rp   r-   r,   <module>r      s[   $ # 	 " > 1 N C & > 4 . $ @ X * )

)DT;2B Dr-   