
    ~ g*                         S SK r S SKrS SKrS SKJrJrJrJrJr  S SK	J
r
   " S S\5      r " S S\\\5      r " S S	\\5      rg)
    N)PluginRedHatPluginDebianPluginUbuntuPlugin	PluginOpt)
RHELPolicyc                   2    \ rS rSrSrSrSrSrSrSr	S r
S	rg
)Python   zfCaptures information on the installed python runtime(s), as well as
python modules installed via pip.
zPython runtimepython)system)r   z	python -Vc                     U R                  U R                  SS9  U R                  S5      nUS   S:X  a2  US   R                  5       SS   H  nU R                  U S35        M     g g )	Nzpython-version)suggest_filenamezwhereis pip -bstatusr   output   z -v list installed)add_cmd_outputpython_versionexec_cmdsplit)selfpipspips      ;/usr/lib/python3/dist-packages/sos/report/plugins/python.pysetupPython.setup!   sy    2B 	 	
 }}-.>Q H~++-ab1##se+=$>? 2	      N)__name__
__module____qualname____firstlineno____doc__
short_descplugin_nameprofilespackagesr   r   __static_attributes__r   r   r   r
   r
      s(     "JKHH N
@r   r
   c                       \ rS rSrSrSrSrg)UbuntuPython.   
python3 -V)python3r   N)r   r    r!   r"   r   r'   r(   r   r   r   r*   r*   .   s    !NHr   r*   c                   N   ^  \ rS rSrSrSr\" SSSS9/rU 4S jrS	 r	S
 r
SrU =r$ )RedHatPython4   a  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                    > U R                  SS/5        [        U R                  [        5      (       a%  U R                  R	                  5       S:X  a  SU l        [        TU ]  5         g )Nz
python2 -Vr,      z/usr/libexec/platform-python -V)r   
isinstancepolicyr   dist_versionr   superr   )r   	__class__s    r   r   RedHatPython.setupA   sM    \<89dkk:..((*a/"CDr   c                     U R                  S5      (       aM  U R                  S5       nUR                  [        R                  " U R                  5       SS95        S S S 5        g g ! , (       d  f       g = f)Nr3   zdigests.json   )indent)
get_optioncollection_filewritejsondumps
get_hashes)r   hfiles     r   collectRedHatPython.collectH   sS    ??8$$%%n5DJJt'8CD 65 %55s   3A%%
A3c           	         S/ 0n/ SQnU H  n[         R                  " U R                  U5      5       H  u  pEnU H  nUR                  S5      (       d  M  U R                  XG5      n [	        US5       n	[
        R                  " 5       n
U	R                  S5      nU(       a+  U
R                  U5        U	R                  S5      nU(       a  M+  U
R                  5       n
US   R                  UU
S.5        SSS5        M     M     M     U$ ! , (       d  f       M  = f! [         a    U R                  SU 35         GM  f = f)	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hashlibrN   readupdate	hexdigestappendIOError
_log_error)r   rK   py_pathspy_pathroot_files_filerM   filedigestdatas               r   rF   RedHatPython.get_hashesM   s/    r

  G"$''$..*A"B"E >>%00 #~~d:H7!(D1T%,^^%5F#'99T?D"& &d 3'+yy #'$ &,%5%5%7F#I.55,4*07  21 # #C  ,  21 # 7(H+3*)6 7 77s7   (D4AD
	'D
	4D

DDDD?	>D?	)r   )r   r    r!   r"   r#   r'   r   option_listr   rH   rF   r(   __classcell__)r<   s   @r   r/   r/   4   s;     OH(E<	>K
E
" "r   r/   )rT   rD   rO   sos.report.pluginsr   r   r   r   r   sos.policies.distros.redhatr   r
   r*   r/   r   r   r   <module>ri      sI      	9 9 2@V @66< ;6< ;r   