o
    O6uf  ã                   @   s*   d dl mZmZmZ G dd„ deeƒZdS )é    )ÚPluginÚRedHatPluginÚ	PluginOptc                   @   sL   e Zd ZdZdZdZdZdZdZe	ddd	d
�gZ
dd„ Zdd„ Zdd„ ZdS )Ú	DNFPluginaü  
    The DNF plugin collects information for the dnf package manager and how it
    is configured for local system.

    By default, this plugin will collect configuration files from /etc/dnf,
    repo files defined in /etc/yum.repos.d/, module information, and various
    'dnf list' commands.

    When using the 'history-info' option, detailed transaction information will
    be collected for the most recent 50 dnf transactions, and will be saved to
    the sos_commands/dnf/history-info directory.
    zdnf package managerÚdnf)ÚsystemÚpackagemanagerÚsysmgmt)ú/etc/dnf/dnf.conf)r   úhistory-infoFz$collect detailed transaction history)ÚdefaultÚdescc                 C   sH   |sdS |  ¡ D ]}d|v r!| ¡ d }|dkr!| jd| dd� qdS )z Get DN module information Nz[i]r   zHint:zdnf module info Údnf_module_info©Útags)Ú
splitlinesÚsplitÚadd_cmd_output)ÚselfÚmodulesÚlineÚmodule© r   ú8/usr/lib/python3/dist-packages/sos/report/plugins/dnf.pyÚget_modules_info(   s   
ÿ€üzDNFPlugin.get_modules_infoc              	   C   sŒ  |   ddi¡ |  g d¢¡ | jdg d¢d� |  d¡r"|  d¡ n|  d	¡ |  d
¡ |  d¡ | jddd� |  g d¢¡ | jdddgd� | jdddgd� |  d¡ |  ddg¡ |  g d¢¡ |  d¡sq| jddd� nE| jddd�}d}|d rž|d  ¡ D ]}zt| d¡d  	¡ ƒ}W  n	 t
y�   Y q„w td t|d  d!ƒƒD ]}| jd"|› �dd#d$� q¨d%}|  |¡}|  |d ¡ d S )&Nz/etc/dnf/modules.d/.*.moduleÚdnf_modules)z	/etc/dnf/z/etc/yum.confz/etc/yum/pluginconf.d/z/etc/yum/vars/z/etc/yum.repos.d/)Úyum_repos_dÚdnf_repos_dÚdnf_repor   Úall_logsz/var/log/dnf.*z/var/log/dnf.log*z/var/log/dnf.librepo.log*z/var/log/dnf.rpm.log*zdnf module listÚdnf_module_list)zdnf --versionzdnf list extraszpackage-cleanup --dupeszpackage-cleanup --problemszdnf list installedÚyum_list_installedÚdnf_list_installedzdnf -C repolistÚyum_repolistÚdnf_repolistzdnf -C repolist --verbosez/etc/pki/entitlement/key.pemz/etc/pki/entitlement/*-key.pem)z/etc/pki/product/*.pemz/etc/pki/consumer/cert.pemz/etc/pki/entitlement/*.pemr   zdnf historyÚdnf_historyéÿÿÿÿÚoutputú|r   é   é2   zdnf history info Údnf_history_info)Úsubdirr   zdnf module list --installed)Úadd_file_tagsÚadd_copy_specÚ
get_optionr   Úadd_forbidden_pathÚcollect_cmd_outputr   Úintr   ÚstripÚ
ValueErrorÚrangeÚminr   )r   ÚhistoryÚtransactionsr   Útr_idÚ
module_cmdr   r   r   r   Úsetup5   sd   ÿÿ



ÿÿÿ
þ
ÿþþ
zDNFPlugin.setupc                 C   s2   d}d}dD ]	}|   |||¡ q|  d||¡ d S )Nz(password(\s)*=(\s)*)(\S+)\nz\1********\n)z/etc/yum.repos.d/*z/etc/dnf/vars/*r
   )Údo_path_regex_subÚdo_file_sub)r   ÚregexpÚreplÚfiler   r   r   Úpostproc€   s
   	zDNFPlugin.postprocN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
short_descÚplugin_nameÚprofilesÚfilesÚpackagesr   Úoption_listr   r;   rA   r   r   r   r   r      s    ÿÿKr   N)Úsos.report.pluginsr   r   r   r   r   r   r   r   Ú<module>   s   
