HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/sos/report/plugins/__pycache__/jars.cpython-38.pyc
U

i��d{�@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)�selfZresultsZ	jar_pathsZ	locationsZuser_locations�location�dirpath�_�	filenames�filenamer�jar_pathr�jar_id�recordZresults_str�r*�9/usr/lib/python3/dist-packages/sos/report/plugins/jars.py�setup1s2





�z
Jars.setupc	Csltj�|�rht�|�rhz6t�|��"}d|��kr@W5QR�WdSW5QRXWnttjfk
rfYnXdS)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.MFTF)	rr�isfile�zipfileZ
is_zipfile�ZipFile�namelist�IOErrorZ
BadZipfile)r�fr*r*r+rTszJars.is_jarcsi}z�t�|���}t�d���fdd�|��D�}t|�dkrNW5QR�WdS|�|d���}|��D]|}|��}|�	d�sfz6|�
d�\}}|�d	���}|�d	���}|||<Wqftk
r�YW5QR�W5QR�WdSXqfW5QRXW5QRXWnt
k
�rYnX|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>ps
z%Jars.get_maven_id.<locals>.<listcomp>�Nr�#�=�utf8)r.r/�re�compiler0�len�open�	readlines�strip�
startswithr�decode�
ValueErrorr1)r'Zpropsr2�resultZprops_f�line�key�valuer*r6r+rds*

:zJars.get_maven_idc	Csld}zNt|dd��0}t��}tt|jd�d�D]}|�|�q.W5QRX|��}Wntk
rfYnX|S)zHCompute JAR id.

        Returns sha1 hash of a given JAR file.
        r
�rb)�modei�)	r@�hashlibr�iterr�read�updateZ	hexdigestr1)r'r(r2�mZbufr*r*r+r�szJars.get_jar_idN)�__name__�
__module__�__qualname__Z
short_descZplugin_nameZprofilesr�strZoption_listrrr,�staticmethodrrrr*r*r*r+rs&���
#

r)rMrrr=r.�	functoolsrZsos.report.pluginsrrrrr*r*r*r+�<module>s