a >h*@szddlZddlZddlZddlmZmZmZmZmZddl m Z GdddeZ Gddde eeZ Gdd d e eZ dS) N)Plugin RedHatPlugin DebianPlugin UbuntuPlugin PluginOpt) RHELPolicyc@s,eZdZdZdZdZdZdZdZddZ d S) PythonznCaptures information on the installed python runtime(s), as well as python modules installed via pip. zPython runtimepython)system)r z python -VcCsT|j|jdd|d}|ddkrP|dddD]}||dq:dS) Nzpython-version)Zsuggest_filenamezwhereis pip -bstatusroutputz -v list installed)add_cmd_outputpython_versionZexec_cmdsplit)selfZpipsZpipr=/usr/lib/python3.9/site-packages/sos/report/plugins/python.pysetup!s  z Python.setupN) __name__ __module__ __qualname____doc__Z short_descZ plugin_nameZprofilespackagesrrrrrrrsrc@seZdZdZdZdS) UbuntuPython python3 -V)python3N)rrrrrrrrrr.srcsDeZdZdZdZeddddgZfddZd d Zd 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 Zpython36Zpython2rzplatform-pythonhashesFz#collect hashes for all python files)defaultZdesccs<|ddgt|jtr.|jdkr.d|_tdS)Nz python2 -Vrz/usr/libexec/platform-python -V)r isinstanceZpolicyrZ dist_versionrsuperr)r __class__rrrAs   zRedHatPython.setupcCsP|drL|d(}|tj|ddWdn1sB0YdS)Nrz digests.json)indent)Z get_optionZcollection_filewritejsondumps get_hashes)rZhfilerrrcollectHs  zRedHatPython.collectc Csdgi}gd}|D]}t||D]\}}}|D]}|dsFq6|||}zvt|dX} t} | d} | r| | | d} qr| } |d || dWdn1s0YWq6t y| d|Yq60q6q(q|S) z! Get the hashes for Python files digests)z/usr/libz /usr/lib64z/usr/local/libz/usr/local/lib64z.pyrbi)filepathsha256NzUnable to read python file at ) oswalkZ path_joinendswithopenhashlibr/readupdateZ hexdigestappendIOErrorZ _log_error) rr,Zpy_pathsZpy_pathroot_filesZ_filer.fileZdigestdatarrrr*Ms4      * zRedHatPython.get_hashes) rrrrrrZ option_listrr+r* __classcell__rrr#rr4s r)r4r(r0Zsos.report.pluginsrrrrrZsos.policies.distros.redhatrrrrrrrr s