U
    *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   sR   | j | jdd | d}|d dkrN|d  dd  D ]}|  d|  q:d S )	Nzpython-version)Zsuggest_filenamezwhereis pip -bZ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                    sB  |  ddg t| jtr.| j dkr.d| _tt|   | 	dr>dg i}ddd	d
g}|D ]}t
| |D ]\}}}|D ]}| ||}|drz`t|dL}	t }
d}|	|}|r|
| qqq|
 }
|d ||
d W 5 Q R X W q tk
r    | d|  Y qX qqtq`| jt|ddd d S )Nz
python2 -Vz
python3 -V   z/usr/libexec/platform-python -Vr   digestsz/usr/libz
/usr/lib64z/usr/local/libz/usr/local/lib64z.pyrbi   )filepathsha256z Unable to read python file at %szdigests.jsonT)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   sT     

zRedHatPython.setup)r   r   r   r   r   Zoption_listr   __classcell__r   r   r4   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   