HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/usr/lib/python3.9/site-packages/sos/report/plugins/__pycache__/jars.cpython-39.pyc
a

^��c{�@s^ddlZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
Gdd�dee	�ZdS)�N)�partial)�Plugin�RedHatPlugin�	PluginOptc@sjeZdZdZdZdZeddedd�edd	d
d�gZdZ	d
Z
dd�Zedd��Z
edd��Zedd��ZdS)�Jarsz1Collect information about available Java archives�jars)�java�append_locations�z,colon-delimited list of additional JAR paths)�defaultZval_type�desc�all_known_locationsFzscan all known paths)rr)z/usr/share/javaz
/usr/lib/java)z/optz
/usr/localz/var/libcCs�dgi}g}ttj�}|�d�r.|ttj�7}|�d�}|rJ||�d�7}|D]D}t�|�D]4\}}}|D]$}	|�||	�}
t�	|
�rj|�
|
�qjq\qN|D]:}t�|�}t�|�}
|s�|
r�||
|d�}|d�
|�q�t
j|ddd�}|j|d	d
d�dS)Nrr
r	�:)�path�sha1�maven_id�)�,z: )�indentZ
separatorsz	jars.jsonT)Zplug_dir)�listr�
jar_locationsZ
get_option�extra_jar_locations�split�os�walkZ	path_join�is_jar�append�get_maven_id�
get_jar_id�json�dumpsZadd_string_as_file)�self�resultsZ	jar_pathsZ	locationsZuser_locations�location�dirpath�_�	filenames�filenamer�jar_pathr�jar_id�recordZresults_str�r+�;/usr/lib/python3.9/site-packages/sos/report/plugins/jars.py�setup1s2





�z
Jars.setupc	Cs�tj�|�r|t�|�r|zLt�|��.}d|��vrBWd�WdSWd�n1sV0YWnttjfyzYn0dS)z�Check whether given file is a JAR file.

        JARs are ZIP files which usually include a manifest
        at the canonical location 'META-INF/MANIFEST.MF'.
        zMETA-INF/MANIFEST.MFNTF)	rr�isfile�zipfile�
is_zipfile�ZipFile�namelist�IOErrorZ
BadZipfile)r�fr+r+r,rTs4zJars.is_jarcsHi}�z(t�|���}t�d���fdd�|��D�}t|�dkrTWd�WdS|�|d���}|��D]~}|��}|�	d�slz6|�
d�\}}|�d	���}|�d	���}|||<Wqlty�YWd�Wd�WdS0qlWd�n1�s0YWd�n1�s"0YWnt
�yBYn0|S)
z�Extract Maven coordinates from a given JAR file, if possible.

        JARs build by Maven (most popular Java build system) contain
        'pom.properties' file. We can extract Maven coordinates
         from there.
        z*META-INF/maven/[^/]+/[^/]+/pom.properties$csg|]}��|�r|�qSr+)�match)�.0�x��rr+r,�
<listcomp>p�z%Jars.get_maven_id.<locals>.<listcomp>�Nr�#�=�utf8)r/r1�re�compiler2�len�open�	readlines�strip�
startswithr�decode�
ValueErrorr3)r(Zpropsr4�resultZprops_f�line�key�valuer+r8r,rds*

jzJars.get_maven_idcCs~d}zbt|dd��:}t��}tt|jd�d�D]}|�|�q.Wd�n1sR0Y|��}WntyxYn0|S)zHCompute JAR id.

        Returns sha1 hash of a given JAR file.
        r
�rb)�modeir;N)	rC�hashlibr�iterr�read�update�	hexdigestr3)r(r)r4�m�bufr+r+r,r�s*zJars.get_jar_idN)�__name__�
__module__�__qualname__Z
short_descZplugin_nameZprofilesr�strZoption_listrrr-�staticmethodrrrr+r+r+r,rs&���
#

r)rOrrr@r/�	functoolsrZsos.report.pluginsrrrrr+r+r+r,�<module>s