HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/__pycache__/hg_pillar.cpython-310.pyc
o

�N�g��@s�dZddlZddlZddlZddlZddlZddlZddlm	Z	zddl
Z
Wney1dZ
Ynwe�e
�ZdZdd�Zdd�Zdd
d�Zdd
�ZGdd�d�ZdS)a�
Use remote Mercurial repository as a Pillar source.

.. versionadded:: 2015.8.0

The module depends on the ``hglib`` python module being available.
This is the same requirement as for hgfs\_ so should not pose any extra
hurdles.

This external Pillar source can be configured in the master config file as such:

.. code-block:: yaml

   ext_pillar:
     - hg: ssh://hg@example.co/user/repo
�N)�DEFAULT_HASH_TYPE�hgcCsBdd�t�dg�D�}tdd�|D��sdStst�d�dStS)z*
    Only load if hglib is available.
    cSsg|]}|�qS�r��.0�xrr�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/pillar/hg_pillar.py�
<listcomp>*sz__virtual__.<locals>.<listcomp>�
ext_pillarcSsg|]}d|v�qS)rrrrrrr	+sFzhglib not present)�__opts__�get�any�hglib�log�error�__virtualname__)Zext_pillar_sourcesrrr�__virtual__&s
rcCsdS)zX
    Initialise

    This is called every time a minion calls this external pillar.
    Nr)rrrr�__init__3sr�defaultc	Cs�t|��
}|�|�Wd�n1swY|dkrdn|}|r0tj�tj�|j|��}n|j}t�t	�}|g|d|<t
j�|t
||�}|jdd�S)z.
    Extract pillar from an hg repository
    Nr�baseZpillar_rootsF)�ext)�Repo�update�os�path�normpath�join�working_dir�copy�deepcopyr�salt�pillarZPillarZ
__grains__Zcompile_pillar)	Z	minion_idr!�repo�branch�rootZenvnamer�optsZpilrrrr
;s
�
r
cCs6t|��
}|��Wd�dS1swYdS)z-
    Execute an hg pull on all the repos
    N)r�pull)�repo_urir"rrrrMs

"�rc@sBeZdZdZdd�Zdd�Zddd�Zd	d
�Zdd�Zd
d�Z	dS)rz?
    Deal with remote hg (mercurial) repository for Pillar
    cCs�||_tj�tdd�}ttt�dt��}|t	j
j�|���
�}tj�||�|_tj�|j�s>t�||j�|_|j��dSt�|j�|_dS)z6Initialize a hg repo (or open it if it already exists)�cachedirZ	hg_pillar�	hash_typeN)r'rrrr�getattr�hashlibrrr �utilsZstringutils�to_bytes�	hexdigestr�isdirr�cloner"�open)�selfr'r(r)Z	repo_hashrrrrZsz
Repo.__init__cCst�d�|j��dS)N�-Updating hg repo from hg_pillar module (pull))r�debugr"r&�r2rrrr&gs
z	Repo.pullrcCs2t�d�|j��t�d�|jj|dd�dS)zN
        Ensure we are using the latest revision in the hg repository
        r3z/Updating hg repo from hg_pillar module (update)T)ZcleanN)rr4r"r&r)r2r#rrrrks


zRepo.updatecCs|j��dS)z2
        Cleanup mercurial command server
        N)r"�closer5rrrr6tsz
Repo.closecCs|S�Nrr5rrr�	__enter__zszRepo.__enter__cCs|��dSr7)r6)r2�exc_type�	exc_value�	tracebackrrr�__exit__}sz
Repo.__exit__N)r)
�__name__�
__module__�__qualname__�__doc__rr&rr6r8r<rrrrrUs
	r)rN)r@rr+�loggingrZsalt.pillarr Zsalt.utils.stringutilsZsalt.configrr�ImportError�	getLoggerr=rrrrr
rrrrrr�<module>s(�