o
    *b                     @   sj   d dl mZmZmZmZmZ d dlmZ d dlZd dl	Z	d dl
Z
G dd deeeZG dd deeZdS )    )PluginRedHatPluginDebianPluginUbuntuPlugin	PluginOpt)
RHELPolicyNc                   @   s(   e Zd ZdZdZdZdZdZdd ZdS )	PythonzPython runtimepython)system)r	   python3z	python -Vc                 C   sV   | j | jdd | d}|d dkr'|d  dd  D ]}|  d|  qd S d S )	Nzpython-version)Zsuggest_filenamezwhereis pip -bstatusr   output   z%s list installed)add_cmd_outputpython_versionZexec_cmdsplit)selfZpipsZpip r   ;/usr/lib/python3/dist-packages/sos/report/plugins/python.pysetup   s   
zPython.setupN)	__name__
__module____qualname__Z
short_descZplugin_nameZprofilespackagesr   r   r   r   r   r   r      s    r   c                       s0   e Zd ZdZeddddgZ fddZ  ZS )RedHatPython)r	   Zpython36Zpython2r   zplatform-pythonhashesFz#collect hashes for all python files)defaultZdescc                    sR  |  ddg t| jtr| j dkrd| _tt|   | 	drdg i}g d}|D ]l}t
| |D ]a\}}}|D ]Y}| ||}|drz;t|d	,}	t }
d
}	 |	|}|rf|
| nnqY|
 }
|d ||
d W d    n1 sw   Y  W q> ty   | d|  Y q>w q>q7q-| jt|ddd d S d S )Nz
python2 -Vz
python3 -V   z/usr/libexec/platform-python -Vr   digests)z/usr/libz
/usr/lib64z/usr/local/libz/usr/local/lib64z.pyrbi   T)filepathsha256z Unable to read python file at %szdigests.json)Zplug_dir)r   
isinstanceZpolicyr   Zdist_versionr   superr   r   Z
get_optionoswalkZ	path_joinendswithopenhashlibr!   readupdateZ	hexdigestappendIOErrorZ
_log_errorZadd_string_as_filejsondumps)r   r   Zpy_pathsZpy_pathroot_filesZfile_r    fZdigestchunkdata	__class__r   r   r   3   s\   




zRedHatPython.setup)r   r   r   r   r   Zoption_listr   __classcell__r   r   r5   r   r   +   s    r   )Zsos.report.pluginsr   r   r   r   r   Zsos.policies.distros.redhatr   r$   r-   r(   r   r   r   r   r   r   <module>   s   
