o
    id                     @   sz   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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Zdd Z	d	S )
PythonznCaptures information on the installed python runtime(s), as well as
    python modules installed via pip.
    zPython runtimepython)system)r	   z	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)suggest_filenamezwhereis pip -bstatusr   output   z%s list installed)add_cmd_outputpython_versionexec_cmdsplit)selfpipspip r   ;/usr/lib/python3/dist-packages/sos/report/plugins/python.pysetup!   s   
zPython.setupN)
__name__
__module____qualname____doc__
short_descplugin_nameprofilespackagesr   r   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdZdS )UbuntuPython
python3 -V)python3N)r   r   r   r   r    r   r   r   r   r!   .   s    r!   c                       sD   e Zd ZdZdZeddddgZ fddZd	d
 Zdd Z	  Z
S )RedHatPythona   In addition to the base information, on Red Hat family distributions the
    python plugin also supports the 'hashes' option. If enabled, this plugin
    will generate a json-formatted listing of all pyfiles within the
    distribution-standard python package installation locations.
    )r	   python36python2r#   zplatform-pythonhashesFz#collect hashes for all python files)defaultdescc                    s@   |  ddg t| jtr| j dkrd| _tt|   d S )Nz
python2 -Vr"      z/usr/libexec/platform-python -V)	r   
isinstancepolicyr   dist_versionr   superr$   r   )r   	__class__r   r   r   A   s
   zRedHatPython.setupc                 C   sV   |  dr)| d}|tj|  dd W d    d S 1 s"w   Y  d S d S )Nr'   zdigests.json   )indent)
get_optioncollection_filewritejsondumps
get_hashes)r   hfiler   r   r   collectH   s
   
"zRedHatPython.collectc                 C   s   dg i}g d}|D ]m}t | |D ]b\}}}|D ]Z}|ds#q| ||}z<t|d-}	t }
|	d}|rG|
| |	d}|s;|
	 }
|d 
||
d W d    n1 s_w   Y  W q tyu   | d|  Y qw qq
|S )Ndigests)z/usr/libz
/usr/lib64z/usr/local/libz/usr/local/lib64z.pyrbi   )filepathsha256z Unable to read python file at %s)oswalk	path_joinendswithopenhashlibr>   readupdate	hexdigestappendIOError
_log_error)r   r;   py_pathspy_pathroot_files_filer=   fdigestdatar   r   r   r8   M   s@   





zRedHatPython.get_hashes)r   r   r   r   r    r   option_listr   r:   r8   __classcell__r   r   r/   r   r$   4   s    r$   )sos.report.pluginsr   r   r   r   r   sos.policies.distros.redhatr   r?   r6   rD   r   r!   r$   r   r   r   r   <module>   s   
