Your IP : 216.73.216.172


Current Path : /lib/python3/dist-packages/sos/report/plugins/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/sos/report/plugins/__pycache__/jars.cpython-38.pyc

U

-�_g��@s^ddlZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
Gdd�dee	�ZdS)�N)�partial)�Plugin�RedHatPlugin�	PluginOptc@s^eZdZdZdZdZeddedd�edd	d
d�gZdZ	d
Z
dd�Zdd�Zdd�Z
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]$}	|�||	�}
|�	|
�rj|�
|
�qjq\qN|D]:}|�|�}|�|�}
|s�|
r�||
|d�}|d�
|�q�t
j|ddd�}|j|d	d
d�dS)Nrr
r	�:)�path�sha1�maven_id�)�,�: )�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
Cs�tj�|�r�t�|�r�z6t�|��"}d|��kr@W5QR�WdSW5QRXWn>ttjfk
r�}z|�	d|�d|���W5d}~XYnXdS)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.MFTzCould not determine if z is a JAR: NF)
rr�isfile�zipfileZ
is_zipfile�ZipFile�namelist�IOErrorZ
BadZipfile�	_log_info)r"r�file�errr+r+r,rTs�zJars.is_jarc
s:i}z�t�|���}t�d���fdd�|��D�}t|�dkrNW5QR�WdS|�|d���}|��D]|}|��}|�	d�sfz6|�
d�\}}|�d	���}|�d	���}|||<Wqftk
r�YW5QR�W5QR�WdSXqfW5QRXW5QRXWn:t
k
�r4}	z|�d
|�d|	���W5d}	~	XYnX|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�Zrgxr+r,�
<listcomp>ps
z%Jars.get_maven_id.<locals>.<listcomp>�Nr�#�=�utf8z)Could not extract Maven coordinates from r)r/r0�re�compiler1�len�open�	readlines�strip�
startswithr�decode�
ValueErrorr2r3)
r"r(Zpropsr4�resultZprops_f�line�key�valuer5r+r9r,res.

:�zJars.get_maven_idc
Cs�d}zNt|dd��0}t��}tt|jd�d�D]}|�|�q.W5QRX|��}Wn8tk
r�}z|�	d|�d|���W5d}~XYnX|S)	zHCompute JAR id.

        Returns sha1 hash of a given JAR file.
        r
�rb)�modei�zCould not compute JAR id for rN)
rB�hashlibr�iterr�read�updateZ	hexdigestr2r3)r"r(r)r4ZdigestZbufr5r+r+r,r�s(zJars.get_jar_idN)�__name__�
__module__�__qualname__Z
short_descZplugin_nameZprofilesr�strZoption_listrrr-rrrr+r+r+r,rs ���
#r)rOr rr?r/�	functoolsrZsos.report.pluginsrrrrr+r+r+r,�<module>s