Sindbad~EG File Manager

Current Path : /lib/python3.6/site-packages/sos/report/plugins/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/sos/report/plugins/__pycache__/jars.cpython-36.opt-1.pyc

3

�f��@s^ddlZddlZddlZddlZddlZddlmZddlmZm	Z	m
Z
Gdd�dee	�ZdS)�N)�partial)�Plugin�RedHatPlugin�	PluginOptc@sjeZdZdZdZdZeddedd�edd	d
d�gZdZ	dZ
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�/usr/share/java�
/usr/lib/java�/opt�
/usr/local�/var/libcCsdgi}g}ttj�}|jd�r.|ttj�7}|jd�}|rJ||jd�7}xT|D]L}xFtj|�D]8\}}}x,|D]$}	|j||	�}
tj	|
�rp|j
|
�qpWq`WqPWxB|D]:}tj|�}tj|�}
|s�|
r�||
|d�}|dj
|�q�Wt
j|dd
d	�}|j|d
dd�dS)Nrr
r	�:)�path�sha1�maven_id��,�: )�indentZ
separatorsz	jars.jsonT)Zplug_dir)rr)�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�r1�/usr/lib/python3.6/jars.py�setup1s0








z
Jars.setupcCs`tjj|�r\tj|�r\y*tj|��}d|j�kr4dSWdQRXWnttjfk
rZYnXdS)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.MFTNF)	rr�isfile�zipfileZ
is_zipfile�ZipFile�namelist�IOErrorZ
BadZipfile)r�filer1r1r2r!TszJars.is_jarc s�i}y�tj|���}tjd���fdd�|j�D�}t|�dkrBdS|j|d��v}xn|j�D]b}|j�}|j	d�s\y6|j
d�\}}|jd	�j�}|jd	�j�}|||<Wq\tk
r�dSXq\WWdQRXWdQRXWnt
k
r�YnX|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|]}�j|�r|�qSr1)�match)�.0�x)�rgxr1r2�
<listcomp>psz%Jars.get_maven_id.<locals>.<listcomp>�Nr�#�=�utf8)r5r6�re�compiler7�len�open�	readlines�strip�
startswithr�decode�
ValueErrorr8)r.Zpropsr9�resultZprops_f�line�key�valuer1)r=r2r#ds*

"zJars.get_maven_idcCspd}yRt|dd��4}tj�}x$tt|jd�d�D]}|j|�q0WWdQRX|j�}Wntk
rjYnX|S)zHCompute JAR id.

        Returns sha1 hash of a given JAR file.
        r
�rb)�modei�N)	rF�hashlibr�iterr�read�updateZ	hexdigestr8)r.r/r9ZdigestZbufr1r1r2r$�szJars.get_jar_idN)r)rr)rrr)�__name__�
__module__�__qualname__Z
short_descZplugin_nameZprofilesr�strZoption_listrrr3�staticmethodr!r#r$r1r1r1r2rs 
#r)rSr%rrCr5�	functoolsrZsos.report.pluginsrrrrr1r1r1r2�<module>s

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists