Ë
    i©¹d  ã                   óŒ   — 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e«      Z G d„ deee«      Z G d„ d	ee«      Zy)
é    )ÚPluginÚRedHatPluginÚDebianPluginÚUbuntuPluginÚ	PluginOpt)Ú
RHELPolicyNc                   ó*   — 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|z  «       Œ y y )	Nzpython-version)Úsuggest_filenamezwhereis pip -bÚstatusr   Úoutputé   z%s 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‘~×+Ñ+Ó-¨a¨bÐ1ò ?�Ø×#Ñ#Ð$7¸#Ñ$=Õ>ñ?ð	 ó    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        t        | �#  «        y )Nz
python2 -Vr'   é   z/usr/libexec/platform-python -V)	r   Ú
isinstanceÚpolicyr   Údist_versionr   Úsuperr*   r   )r   Ú	__class__s    €r   r   zRedHatPython.setupA   sN   ø€ Ø×Ñ˜\¨<Ð8Ô9Ü�d—k‘k¤:Ô.Ø—‘×(Ñ(Ó*¨aÒ/Ø"CˆDÔÜŒl˜DÑ'Õ)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¸Ø—‘œDŸJ™J t§¡Ó'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|z  «       Y Œãw xY w)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ÚhashlibrF   ÚreadÚupdateÚ	hexdigestÚappendÚIOErrorÚ
_log_error)r   rC   Úpy_pathsÚpy_pathÚrootÚ_ÚfilesÚ_filerE   ÚfÚdigestÚdatas               r   r?   zRedHatPython.get_hashesM   s8  € à�rð
ˆò
ˆð  ò 	4ˆGÜ"$§'¡'¨$¯.©.¸Ó*AÓ"Bò 4‘��a˜Ø"ò 4�EØ Ÿ>™>¨%Ô0Ø Ø#Ÿ~™~¨d°EÓ:�Hð4Ü! (¨DÓ1ð °QÜ%,§^¡^Ó%5˜FØ#$§6¡6¨$£<˜DÙ"&Ø &§¡¨dÔ 3Ø'(§v¡v¨d£| ò #'ð &,×%5Ñ%5Ó%7˜FØ# IÑ.×5Ñ5Ø,4Ø*0ñ7ô ÷øñ4ñ4ð	4ð, ˆ÷ð ûô #ò 4ØŸ™Ð(JØ*2ñ)3ö 4ð4ús1   Á#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*   )Úsos.report.pluginsr   r   r   r   r   Úsos.policies.distros.redhatr   rG   r=   rL   r
   r&   r*   r$   r   r   ú<module>r`      sE   ð÷9õ 9å 2Û 	Û Û ô?ˆVô ?ô6�6˜<¨ô ô:�6˜<õ :r   