o nnhS@sdZddlmZddlZddlZddlZddlZddlZddl m Z m Z ddl m Z ddlmZddlmZmZmZmZd d lmZd ZGd d d eZGdddeZGdddZdS)z9Support code for working without a supported CI provider.) annotationsN) CommonConfig TestConfig)read_text_file)Git)ApplicationErrordisplayis_binary_fileSubprocessError) CIProviderc@seZdZdZdZed!ddZed"dd Zed"d d Z d"d d Z d#ddZ d$ddZ d!ddZ d%ddZd&ddZed"ddZd S)'Localz-CI provider implementation when not using CI.ireturnboolcCdS)zMReturn True if this provider is supported in the current running environment.TrrrJ/usr/local/lib/python3.10/dist-packages/ansible_test/_internal/ci/local.py is_supported*zLocal.is_supportedstrcCstS)z0Return a unique code representing this provider.)CODEselfrrrcode/rz Local.codecCr)z*Return descriptive name for this provider.rrrrrrname4rz Local.namecCs&dtddtddf}|S)z6Return a resource prefix specific to this CI provider.zansible-test-%d-%sii.r)randomrandintplatformnodesplit)rprefixrrrgenerate_resource_prefix9s  zLocal.generate_resource_prefixargsrcCr)z*Return the base commit or an empty string.rrrr%rrrget_base_commitBzLocal.get_base_commitrt.Optional[list[str]]cCsnt|}td|j|j|jf|jr!|js!tdt|j|j r1|j s1tdt|j |j rA|j sAtdt|j |j rQ|j sQtdt|j t }|j r^|t |j O}|jrh|t |jO}|j rr|t |j O}|j r||t |j O}|j r|t |j O}|jjs|j|j|jD]}t|rd|jj|<qtt|}d|ff|jj|<qt|S)zInitialize change detection.z.Detected branch %s forked from %s at commit %sz>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.))rrr ) LocalChangesr infocurrent_branch fork_branch fork_point untrackedwarninglen committedstagedunstagedsettrackedmetadatachangespopulate_changesdiffr r splitlinessorted)rr%resultnamespath line_countrrrdetect_changesFsP       zLocal.detect_changescCs|}tj|S)z,Return True if Ansible Core CI is supported.)_get_aci_key_pathosr?exists)rr?rrrsupports_core_ci_authxs zLocal.supports_core_ci_authdict[str, t.Any]cCs.|}t|}t|dd}t|d}|S)z2Return authentication details for Ansible Core CI.N)keynonce)remote)rBrstripdict)rr?auth_keyrequestauthrrrprepare_core_ci_auth}s zLocal.prepare_core_ci_autht.Optional[dict[str, t.Any]]cCr)z4Return details about git in the current environment.Nrr&rrrget_git_detailsr(zLocal.get_git_detailscCstjd}|S)Nz~/.ansible-core-ci.key)rCr? expanduser)r?rrrrBs zLocal._get_aci_key_pathN)rr)rr)r%rrr)r%rrr))rrF)r%rrrP)__name__ __module__ __qualname____doc__priority staticmethodrpropertyrrr$r'rArErOrQrBrrrrr%s"      2  rcs"eZdZdZd fdd ZZS) InvalidBranchz+Exception for invalid branch specification.branchrreasonrNonecs"d||f}t|||_dS)NzInvalid branch: %s %s)super__init__r[)rr[r\message __class__rrr_s   zInvalidBranch.__init__)r[rr\rrr])rSrTrUrVr_ __classcell__rrrarrZsrZc@s$eZdZdZdddZdd d Zd S)r*z"Change information for local work.r%rrr]c s0|_t_j_jrtjddd_d_t j _ t fddj D_ j D]_z j j_Wn tyOYq8wjdurYtdt jdg_t jddg_t jjd g_t jdg_t jg_jjg_dS) Nz'Current branch is not a feature branch.)r[r\csg|] }|r|qSr)is_official_branch).0brrr sz)LocalChanges.__init__..z1Unable to auto-detect fork branch and fork point.z--cachedz--othersz--exclude-standardHEAD)r%rgit get_branchr,rdrZr-r.r< get_brancheslocal_branchesofficial_branchesget_branch_fork_pointr rget_file_namesr6r/get_diff_namesr2r3r4get_diffr:r&rrrr_s4     zLocalChanges.__init__rrrcCs4|jjr ||jjkS|dkrdStd|rdSdS)zTReturn True if the given branch name an official branch for development or releases.develTz^stable-[0-9]+\.[0-9]+$F)r% base_branchrematch)rrrrrrds  zLocalChanges.is_official_branchN)r%rrr])rrrr)rSrTrUrVr_rdrrrrr*s 'r*)rV __future__rrCr rrttypingtconfigrriorrirutilrr r r rr rrrZr*rrrrs     r