U
    -_g                     @   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)systemZpackagemanagerZsysmgmt)/etc/dnf/dnf.conf)r   history-infoFz$collect detailed transaction history)defaultZdescc                 C   sH   |sdS |  D ]2}d|k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 Z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 | ddddg | jddd	d
gd | drJ| d n| d | d | d | jddd | ddddg | jdddgd | jdddgd | d | ddg | d d!d"g | d#s| jd$d%d n| jd$d%d}d&}|d' rX|d'  D ]@}z"t|d(d) 	 }W  qXW n t
k
rR   Y nX qtd*t|d* d+D ]}| jd,| d#d-d. qld/}| |}| |d'  d S )0Nz/etc/dnf/modules.d/.*.moduleZdnf_modulesz	/etc/dnf/z/etc/yum.confz/etc/yum/pluginconf.d/z/etc/yum/vars/z/etc/yum.repos.d/Zyum_repos_dZdnf_repos_dZdnf_repor   Z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 listZdnf_module_listzdnf --versionzdnf list extraszpackage-cleanup --dupeszpackage-cleanup --problemszdnf list installedZyum_list_installedZdnf_list_installedzdnf -C repolistZyum_repolistZdnf_repolistzdnf -C repolist --verbosez/etc/pki/entitlement/key.pemz/etc/pki/entitlement/*-key.pemz/etc/pki/product/*.pemz/etc/pki/consumer/cert.pemz/etc/pki/entitlement/*.pemr	   zdnf historyZdnf_historyoutput|r      2   zdnf history info Zdnf_history_info)Zsubdirr   zdnf module list --installed)Zadd_file_tagsZadd_copy_specZ
get_optionr   Zadd_forbidden_pathZcollect_cmd_outputr   intr   strip
ValueErrorrangeminr   )r   historyZtransactionsr   Ztr_idZ
module_cmdr   r   r   r   setup5   s     









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   )Zdo_path_regex_subZdo_file_sub)r   Zregexpreplfiler   r   r   postproc   s
    	zDNFPlugin.postprocN)__name__
__module____qualname____doc__Z
short_descZplugin_nameZprofilesfilesZpackagesr   Zoption_listr   r"   r%   r   r   r   r   r      s   Kr   N)Zsos.report.pluginsr   r   r   r   r   r   r   r   <module>   s   