File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/states/__pycache__/augeas.cpython-310.pyc
o
�N�g-* � @ sx d Z ddlZddlZddlZddlZddlZddlZddl Zddl
mZ e�e
�Zdd� Zdd� Zdd � Zdd
d�ZdS )
at
Configuration management using Augeas
.. versionadded:: 0.17.0
This state requires the ``augeas`` Python module.
.. _Augeas: http://augeas.net/
Augeas_ can be used to manage configuration files.
.. warning::
Minimal installations of Debian and Ubuntu have been seen to have packaging
bugs with python-augeas, causing the augeas module to fail to import. If
the minion has the augeas module installed, and the state fails with a
comment saying that the state is unavailable, first restart the salt-minion
service. If the problem persists past that, the following command can be
run from the master to determine what is causing the import to fail:
.. code-block:: bash
salt minion-id cmd.run 'python -c "from augeas import Augeas"'
For affected Debian/Ubuntu hosts, installing ``libpython2.7`` has been
known to resolve the issue.
� N)�
METHOD_MAPc C s dt v rdS dS )N�augeas.executeZaugeas)Fz!augeas module could not be loaded)�__salt__� r r �F/opt/saltstack/salt/lib/python3.10/site-packages/salt/states/augeas.py�__virtual__+ s r c C s4 t j�| �s
| dkr| dkrd} | S tt j�| ��S )zA
Recursively workout the file name from an augeas change
�/N)�os�path�isfile�_workout_filename�dirname)�filenamer r r r 1 s
r c C s d}| D ]�}zZ|� dd�\}}|tvrd|� d�}t|��t| }tjj�|�}|dv r1|d }n|\} } }|�d�sDd �|�}t|��t �
d
d|�}|dur]||kr]d�||�}t|��|}W q ttfy� }
zt�
|
� d
t� vr}d�|�}t|��t|
�}t|��d}
~
ww t|�}|S )z�
Ensure all changes are fully qualified and affect only one file.
This ensures that the diff output works and a state change is not
incorrectly reported.
N� � zCommand z is not supported (yet))�setZsetm�move�remover z/fileszLChanges should be prefixed with /files if no context is provided, change: {}�
^/files|/$� zKChanges should be made to one file at a time, detected changes to {} and {}�errorz8Invalid formatted command, see debug log for details: {})�splitr �
ValueError�salt�utils�argsZshlex_split�
startswith�format�re�sub�
IndexError�logr �locals�strr )�changesr Zchange_�cmd�argr �method�partsZ filename_�_�errr r r �_check_filepath= sN
��
�����r+ c
K sJ | ddi d�}|rt |t�sd|d<