/
lib
/
python3.9
/
site-packages
/
dnf-plugins
/
__pycache__
/
Upload File
HOME
a �&cY � @ sZ d Z ddlmZmZ ddlZddlZddlZddlZddl Z ddl Z G dd� dej�ZdS )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. � )�_�loggerNc s@ e Zd ZdZ� fdd�Zdd� Zdd� Zdd � Zd d� Z� Z S )�PostTransactionActionszpost-transaction-actionsc s( t t| ��||� d| _|| _t| _d S )Nz,/etc/dnf/plugins/post-transaction-actions.d/)�superr �__init__� actiondir�baser )�selfr Zcli�� __class__� �H/usr/lib/python3.9/site-packages/dnf-plugins/post-transaction-actions.pyr + s zPostTransactionActions.__init__c C s6 | � | jj�}|�d�r2|�dd�r2|�dd�| _d S )N�mainr )Zread_configr �confZhas_sectionZ has_option�getr )r r r r r �config1 s zPostTransactionActions.configc C s� g }t �| jt j�r*|�t�| jd �� g }|D ]�}t|��� D ]�}|�� }|rB|d dkrBz|� dd�\}}}W nH t y� } z0| j�t d�||f � W Y d}~qBW Y d}~qBd}~0 0 |�|||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_keyZaction_stateZaction_command�er r r �_parse_actions7 s "z%PostTransactionActions._parse_actionsc C s� t jjdt jjdt jjdt jjdt jjdt jjdt jjdt jj dt jj d t jjd 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�removeZupgradeZupgradedzunknown - %s)�name�archZver�rel�epochZrepoid�state)�dnf�transactionZ PKG_DOWNGRADEZPKG_DOWNGRADEDZPKG_INSTALLZPKG_OBSOLETEZ PKG_OBSOLETEDZ PKG_REINSTALLZPKG_REINSTALLEDZ PKG_REMOVEZPKG_UPGRADEZPKG_UPGRADEDr �actionr( r) �version�release�strr+ Z from_repo�libdnfr ZConfigParser_substitute)r �ts_item�commandZaction_dictr/ Zvardict�resultr r r � _replace_varsN s, ��z$PostTransactionActions._replace_varsc s� | � � }g }g }g }| jjD ]D}|jtjjv r:|�|� n|jtjjv r|�|� 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�| � W n> t�y� } z$| j� t d�||f � W Y d }~n d }~0 0 �qRd S )N�in�out�anyzBad Transaction State: %sc S s g | ] }|j �qS r ��pkg��.0Ztsir r r � <listcomp>� � z6PostTransactionActions.transaction.<locals>.<listcomp>r; TF)Z with_nevraZ with_providesZwith_filenames�queryc s( g | ] }|j � kr|j j� jkr|�qS r )r<