
    VhS                        d Z ddlmZ ddlZddlZddlZddl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mZmZmZ d	d
lmZ dZ G d de      Z G d de      Z G d d      Zy)z9Support code for working without a supported CI provider.    )annotationsN   )CommonConfig
TestConfig)read_text_file)Git)ApplicationErrordisplayis_binary_fileSubprocessError   )
CIProvider c                      e Zd ZdZdZedd       Zedd       Zedd       Z	ddZ
ddZddZdd	Zdd
ZddZedd       Zy)Localz-CI provider implementation when not using CI.i  c                      y)zMReturn True if this provider is supported in the current running environment.T r       O/home/dcms/DCMS/lib/python3.12/site-packages/ansible_test/_internal/ci/local.pyis_supportedzLocal.is_supported*   s     r   c                    t         S )z0Return a unique code representing this provider.)CODEselfs    r   codez
Local.code/   s	     r   c                     y)z*Return descriptive name for this provider.r   r   r   s    r   namez
Local.name4   s     r   c                    dt        j                  dd      t        j                         j	                  d      d   fz  }|S )z6Return a resource prefix specific to this CI provider.zansible-test-%d-%si i.r   )randomrandintplatformnodesplit)r   prefixs     r   generate_resource_prefixzLocal.generate_resource_prefix9   s?    %NN8X.MMO!!#&q))
 

 r   c                     y)z*Return the base commit or an empty string.r   r   r   argss     r   get_base_commitzLocal.get_base_commitB   s    r   c                   t        |      }t        j                  d|j                  d|j                  d|j
                         |j                  r7|j                  s+t        j                  dt        |j                        z         |j                  r7|j                  s+t        j                  dt        |j                        z         |j                  r7|j                  s+t        j                  dt        |j                        z         |j                  r7|j                  s+t        j                  dt        |j                        z         t               }|j                  r|t        |j                        z  }|j                  r|t        |j                        z  }|j                  r|t        |j                        z  }|j                  r|t        |j                        z  }|j                  r|t        |j                        z  }|j                  j                  s|j                  j!                  |j"                         |j                  D ]e  }t%        |      rd|j                  j                  |<   (t        t'        |      j)                               }d	|ff|j                  j                  |<   g t+        |      S )
zInitialize change detection.zDetected branch z forked from z at commit z>Ignored %s untracked file(s). Use --untracked to include them.zHIgnored %s committed change(s). Omit --ignore-committed to include them.zBIgnored %s staged change(s). Omit --ignore-staged to include them.zFIgnored %s unstaged change(s). Omit --ignore-unstaged to include them.))r   r   r   )LocalChangesr
   infocurrent_branchfork_branch
fork_point	untrackedwarninglen	committedstagedunstagedsettrackedmetadatachangespopulate_changesdiffr   r   
splitlinessorted)r   r)   resultnamespath
line_counts         r   detect_changeszLocal.detect_changesF   s#   d#!!6#5#5v7H7HJ 	K DNNOO\ 0 012 3 DNNOOf 0 012 3 ==OO`./ 0 ??4==OOd01 2 <<S((E>>S))**E>>S))**E;;S''E==S))E}}$$MM**6;;7(( A!$'2;DMM))$/ !5!@!@!BC
01:.@%%d+A e}r   c                `    | j                         }t        j                  j                  |      S )z,Return True if Ansible Core CI is supported.)_get_aci_key_pathosrA   exists)r   rA   s     r   supports_core_ci_authzLocal.supports_core_ci_authx   s#    %%'ww~~d##r   c                    | j                         }t        |      j                         }t        |d      }t        |      }|S )z2Return authentication details for Ansible Core CI.N)keynonce)remote)rE   r   stripdict)r   rA   auth_keyrequestauths        r   prepare_core_ci_authzLocal.prepare_core_ci_auth}   sI    %%'!$'--/

 
 r   c                     y)z4Return details about git in the current environment.Nr   r(   s     r   get_git_detailszLocal.get_git_details   s    r   c                 D    t         j                  j                  d      } | S )Nz~/.ansible-core-ci.key)rF   rA   
expanduser)rA   s    r   rE   zLocal._get_aci_key_path   s    ww!!":;r   N)returnbool)rW   str)r)   r   rW   rY   )r)   r   rW   zt.Optional[list[str]])rW   zdict[str, t.Any])r)   r   rW   zt.Optional[dict[str, t.Any]])__name__
__module____qualname____doc__prioritystaticmethodr   propertyr   r   r&   r*   rC   rH   rR   rT   rE   r   r   r   r   r   %   sw    7H     0d$
   r   r   c                  $     e Zd ZdZd fdZ xZS )InvalidBranchz+Exception for invalid branch specification.c                B    d|d|}t         |   |       || _        y )NzInvalid branch: 
)super__init__branch)r   rg   reasonmessage	__class__s       r   rf   zInvalidBranch.__init__   s!    .4f=!r   )rg   rY   rh   rY   rW   None)rZ   r[   r\   r]   rf   __classcell__)rj   s   @r   rb   rb      s    5 r   rb   c                       e Zd ZdZddZddZy)r,   z"Change information for local work.c                   || _         t               | _        | j                  j                         | _        | j                  | j                        rt        | j                  d      d | _        d | _        t        | j                  j                               | _        t        | j                  D cg c]  }| j                  |      s| c}      | _        | j                  D ]3  | _        	 | j                  j                  | j                        | _         n | j                  t        d      t        | j                  j!                  dg            | _        t        | j                  j!                  ddg            | _        t        | j                  j'                  | j                  dg            | _        t        | j                  j'                  dg            | _        t        | j                  j'                  g             | _        | j                  j/                  | j                  g      | _        y c c}w # t        $ r Y gw xY w)Nz'Current branch is not a feature branch.)rg   rh   z1Unable to auto-detect fork branch and fork point.z--cachedz--othersz--exclude-standardHEAD)r)   r   git
get_branchr.   is_official_branchrb   r/   r0   r>   get_brancheslocal_branchesofficial_branchesget_branch_fork_pointr   r	   get_file_namesr8   r1   get_diff_namesr4   r5   r6   get_diffr<   )r   r)   bs      r   rf   zLocalChanges.__init__   s   	5"hh113""4#6#67t':':'PR R  $TXX%:%:%<=!'D4G4G(fq4KbKbcdKe(f!g $ 6 6 	D"&(("@"@AQAQ"R	 ??""#VWW dhh55zlCD 7 7EY8Z [\ 7 7&8Q RSTXX44j\BCtxx66r:;HH%%t&78	/ )g # s   1H:H:-*H??	IIc                    | j                   j                  r|| j                   j                  k(  S |dk(  ryt        j                  d|      ryy)zTReturn True if the given branch name an official branch for development or releases.develTz^stable-[0-9]+\.[0-9]+$F)r)   base_branchrematch)r   r   s     r   rr   zLocalChanges.is_official_branch   sC    99  49900007?88.5r   N)r)   r   rW   rk   )r   rY   rW   rX   )rZ   r[   r\   r]   rf   rr   r   r   r   r,   r,      s    ,%9Nr   r,   )r]   
__future__r   rF   r"   r    r~   typingtconfigr   r   ior   rp   r   utilr	   r
   r   r   r   r   r   r   rb   r,   r   r   r   <module>r      se    ? " 	   	 
  
oJ od$ 5 5r   