U
    -_g'                     @   sz   d dl Z d dlZd dlZd dlmZmZmZmZmZ d dl	m
Z
 G dd deZG dd deeeZG dd	 d	eeZdS )
    N)PluginRedHatPluginDebianPluginUbuntuPlugin	PluginOpt)
RHELPolicyc                   @   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   sT   | j | jdd | d}|d dkrP|d  dd  D ]}|  | d q:d S )	Nzpython-version)Zsuggest_filenamezwhereis pip -bZstatusr   output   z 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____doc__Z
short_descZplugin_nameZ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	   Zpython36Zpython2r   zplatform-pythonhashesFz#collect hashes for all python files)defaultZdescc                    s<   |  ddg t| jtr.| j dkr.d| _t   d S )Nz
python2 -Vr      z/usr/libexec/platform-python -V)r   
isinstanceZpolicyr   Zdist_versionr   superr   )r   	__class__r   r   r   A   s    zRedHatPython.setupc              	   C   s<   |  dr8| d}|tj|  dd W 5 Q R X d S )Nr   zdigests.json   )indent)Z
get_optionZcollection_filewritejsondumps
get_hashes)r   Zhfiler   r   r   collectH   s    
zRedHatPython.collectc                 C   s   dg i}ddddg}|D ]}t | |D ]\}}}|D ]}|dsJq:| ||}zbt|dN}	t }
|	d}|r|
| |	d}qv|
	 }
|d 
||
d	 W 5 Q R X W q: tk
r   | d
|  Y q:X q:q,q|S )z! Get the hashes for Python files digestsz/usr/libz
/usr/lib64z/usr/local/libz/usr/local/lib64z.pyrbi   )filepathsha256zUnable to read python file at )oswalkZ	path_joinendswithopenhashlibr.   readupdateZ	hexdigestappendIOErrorZ
_log_error)r   r+   Zpy_pathsZpy_pathroot_filesZ_filer-   fileZdigestdatar   r   r   r)   M   s:     


zRedHatPython.get_hashes)r   r   r   r   r   r   Zoption_listr   r*   r)   __classcell__r   r   r"   r   r   4   s   r   )r3   r'   r/   Zsos.report.pluginsr   r   r   r   r   Zsos.policies.distros.redhatr   r   r   r   r   r   r   r   <module>   s   