
    -_g'                         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e      Z G d deee      Z G d d	ee      Zy)
    N)PluginRedHatPluginDebianPluginUbuntuPlugin	PluginOpt)
RHELPolicyc                   *    e Zd ZdZdZdZdZdZdZd Z	y)	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                     | j                  | j                  d       | j                  d      }|d   dk(  r0|d   j                         dd  D ]  }| j                  | d        y y )	Nzpython-version)suggest_filenamezwhereis pip -bstatusr   output   z list installed)add_cmd_outputpython_versionexec_cmdsplit)selfpipspips      ;/usr/lib/python3/dist-packages/sos/report/plugins/python.pysetupzPython.setup!   s}    2B 	 	
 }}-.>Q H~++-ab1 =##se?$;<=	     N)
__name__
__module____qualname____doc__
short_descplugin_nameprofilespackagesr   r    r   r   r
   r
      s'     "JKHH N
=r   r
   c                       e Zd ZdZdZy)UbuntuPython
python3 -V)python3N)r   r   r   r   r#   r$   r   r   r&   r&   .   s    !NHr   r&   c                   J     e Zd ZdZdZ eddd      gZ fdZd Zd	 Z	 x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                     | j                  ddg       t        | j                  t              r$| j                  j	                         dk(  rd| _        t        |           y )Nz
python2 -Vr'      z/usr/libexec/platform-python -V)r   
isinstancepolicyr   dist_versionr   superr   )r   	__class__s    r   r   zRedHatPython.setupA   sJ    \<89dkk:.((*a/"CDr   c                     | j                  d      rO| j                  d      5 }|j                  t        j                  | j                         d             d d d        y y # 1 sw Y   y xY w)Nr-   zdigests.json   )indent)
get_optioncollection_filewritejsondumps
get_hashes)r   hfiles     r   collectzRedHatPython.collectH   s`    ??8$%%n5 EDJJt'8CDE E %E Es   5A""A+c           	      D   dg i}g d}|D ]  }t        j                  | j                  |            D ]  \  }}}|D ]  }|j                  d      s| j                  ||      }	 t	        |d      5 }	t        j                         }
|	j                  d      }|r%|
j                  |       |	j                  d      }|r%|
j                         }
|d   j                  ||
d       ddd          |S # 1 sw Y   xY w# t        $ r | j                  d|        Y w xY w)	z! Get the hashes for Python files digests)z/usr/libz
/usr/lib64z/usr/local/libz/usr/local/lib64z.pyrbi   )filepathsha256NzUnable to read python file at )oswalk	path_joinendswithopenhashlibrF   readupdate	hexdigestappendIOError
_log_error)r   rC   py_pathspy_pathroot_files_filerE   filedigestdatas               r   r?   zRedHatPython.get_hashesM   s<    r

   	7G"$''$..*A"B 7a" 7E >>%0 #~~dE:H7!(D1 T%,^^%5F#'99T?D"& &d 3'+yy #' &,%5%5%7F#I.55,4*07 77	7,   # 7(H+3*)6 77s1   #C?/AC3	<'C3	#C?3C<8C??D	D	)r   r   r   r   r#   r   option_listr   rA   r?   __classcell__)r6   s   @r   r*   r*   4   s6     OH(E<	>K
E
"r   r*   )rL   r=   rG   sos.report.pluginsr   r   r   r   r   sos.policies.distros.redhatr   r
   r&   r*   r$   r   r   <module>r`      sG      	9 9 2=V =66< ;6< ;r   