����JFIF��`�`�����Viewing File: /lib/python3.9/site-packages/dnf-plugins/__pycache__/post-transaction-actions.cpython-39.pyc
a

�&cY�@sZdZddlmZmZddlZddlZddlZddlZddl	Z	ddl
Z
Gdd�dej�ZdS)a
The plugin allows to define actions to be executed upon completing an RPM transaction. Each action
may define a (glob-like) filtering rule on the package NEVRA or package files, as well as whether
the package was installed or removed. Actions are defined in action files.

The action can start any shell command. Commands can contain variables. The same command (after
variables substitution) is executed only once per transaction. The order of execution
of the commands may differ from the order of the packages in the transaction.
�)�_�loggerNcs@eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z�Z	S)�PostTransactionActionszpost-transaction-actionscs(tt|��||�d|_||_t|_dS)Nz,/etc/dnf/plugins/post-transaction-actions.d/)�superr�__init__�	actiondir�baser)�selfrZcli��	__class__��H/usr/lib/python3.9/site-packages/dnf-plugins/post-transaction-actions.pyr+szPostTransactionActions.__init__cCs6|�|jj�}|�d�r2|�dd�r2|�dd�|_dS)N�mainr)Zread_configr�confZhas_sectionZ
has_option�getr)r	rrrr
�config1s
zPostTransactionActions.configc	Cs�g}t�|jtj�r*|�t�|jd��g}|D]�}t|���D]�}|��}|rB|ddkrBz|�	dd�\}}}WnHt
y�}z0|j�t
d�||f�WYd}~qBWYd}~qBd}~00|�|||f�qBq2|S)zfParses *.action files from self.actiondir path.
        Parsed actions are stored in a list of tuples.z*.actionr�#�:�zBad Action Line "%s": %sN)�os�accessr�R_OK�extend�glob�open�	readlines�strip�split�
ValueErrorr�errorr�append)	r	Zaction_file_list�
action_tuples�	file_name�lineZ
action_keyZaction_stateZaction_command�errr
�_parse_actions7s"z%PostTransactionActions._parse_actionscCs�tjjdtjjdtjjdtjjdtjjdtjjdtjjdtjj	dtjj
d	tjjd
i
}|�|j
d|j
�}|j|j|j|jt|j�|j|d�}tj�||�}|S)
z�Replaces variables in the command.
        Variables: ${name}, ${arch}, ${ver}, ${rel}, ${epoch}, ${repoid}, ${state}
        or $name, $arch, $ver, $rel, $epoch, $repoid, $stateZ	downgradeZ
downgraded�installZobsoleteZ	obsoletedZ	reinstallZreinstalled�removeZupgradeZupgradedzunknown - %s)�name�archZver�rel�epochZrepoid�state)�dnf�transactionZ
PKG_DOWNGRADEZPKG_DOWNGRADEDZPKG_INSTALLZPKG_OBSOLETEZ
PKG_OBSOLETEDZ
PKG_REINSTALLZPKG_REINSTALLEDZ
PKG_REMOVEZPKG_UPGRADEZPKG_UPGRADEDr�actionr(r)�version�release�strr+Z	from_repo�libdnfrZConfigParser_substitute)r	�ts_item�commandZaction_dictr/Zvardict�resultrrr
�
_replace_varsNs,��z$PostTransactionActions._replace_varscs�|��}g}g}g}|jjD]D}|jtjjvr:|�|�n|jtjjvr|�|�nq|�|�qg}|D]�\}}}	|dkr�|}
n2|dkr�|}
n$|dkr�|}
n|j�	t
d�|�qjtj�|�}dd�|
D�}|jj
��j|d�}
|j|jj
dd	d|
d
�}
|
D]4��fdd�|
D�}|d}|�||	�}|�|�q�qjt���fd
d�|D�}|D]�}z^tj|dtjtjddd�}|��\}}|�r�|j�t
d�|�|�r�|j�	t
d�|�Wn>t�y�}z$|j�	t
d�||f�WYd}~n
d}~00�qRdS)N�in�out�anyzBad Transaction State: %scSsg|]
}|j�qSr��pkg��.0Ztsirrr
�
<listcomp>��z6PostTransactionActions.transaction.<locals>.<listcomp>r;TF)Z
with_nevraZ
with_providesZwith_filenames�querycs(g|] }|j�kr|jj�jkr|�qSr)r<Zreponamer=r;rr
r?�s�rcs"g|]}|�vr��|�s|�qSr)�add)r>�x)�seenrr
r?�r@)�shell�stdout�stderrZ	close_fdsZuniversal_newlineszpost-transaction-actions: %sz.post-transaction-actions: Bad Command "%s": %s)r%rr.r/r-ZFORWARD_ACTIONSr ZBACKWARD_ACTIONSrrrZsubjectZSubjectZsackrAZfiltermZget_best_queryr7�set�
subprocess�Popen�PIPEZcommunicate�info�	Exception)r	r!Zin_ts_itemsZout_ts_itemsZall_ts_itemsr4Zcommands_to_runZa_keyZa_stateZ	a_commandZts_itemsZsubjZpkgsrAZts_item_listr5�procrFrGr$r)r<rDr
r.ksb���z"PostTransactionActions.transaction)
�__name__�
__module__�__qualname__r(rrr%r7r.�
__classcell__rrr
r
r'sr)
�__doc__ZdnfpluginscorerrZlibdnf.confr3r-Zdnf.transactionrrrIZPluginrrrrr
�<module>s

Back to Directory �������}�!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz�������������������������������������������������������������������������������� ������w�!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz������������������������������������������������������������������������ ��?��_��+��?��(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(���(�����