�
i��d{ � �d � d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZm Z m
Z
G d� dee � Zy)� N)�partial)�Plugin�RedHatPlugin� PluginOptc � � e Zd ZdZdZdZ edded�� edd d
�� gZdZ d
Z
d� Zed� � Z
ed� � Zed� � Zy)�Jarsz1Collect information about available Java archives�jars)�java�append_locations� z,colon-delimited list of additional JAR paths)�default�val_type�desc�all_known_locationsFzscan all known paths)r
r )z/usr/share/javaz
/usr/lib/java)z/optz
/usr/localz/var/libc � � dg i}g }t t j � }| j d� r|t t j � z
}| j d� }|r||j d� z
}|D ]` }t
j |� D ]F \ }}}|D ]; } | j || � }
t j |
� s�+|j |
� �= �H �b |D ]K }t j |� }t j |� }
|s|
s�2||
|d�}|d j |� �M t j |dd�� }| j |d d
�� y )Nr r r �:)�path�sha1�maven_id� )�,z: )�indent�
separatorsz jars.jsonT)�plug_dir)�listr �
jar_locations�
get_option�extra_jar_locations�split�os�walk� path_join�is_jar�append�get_maven_id�
get_jar_id�json�dumps�add_string_as_file)�self�results� jar_paths� locations�user_locations�location�dirpath�_� filenames�filenamer �jar_pathr �jar_id�record�results_strs �9/usr/lib/python3/dist-packages/sos/report/plugins/jars.py�setupz
Jars.setup1 sU � ��2�,��� ���+�+�,� ��?�?�0�1���d�6�6�7�7�I� ���);�<�����-�-�c�2�2�I� "� /�H�)+����):�
/�%���I� )� /�H��>�>�'�8�<�D��{�{�4�(�!�(�(��.�/�
/� /� "� /�H��(�(��2�H��_�_�X�.�F��6�"*�"(�&.��� ���&�&�v�.� /� �j�j���{�K������[�4��H� c �< � t j j | � rRt j | � r= t j
| � 5 }d|j
� v r
ddd� y ddd� yy# 1 sw Y yxY w# t t j f$ r Y yw xY w)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) r r �isfile�zipfile�
is_zipfile�ZipFile�namelist�IOError�
BadZipfile)r �fs r8 r# zJars.is_jarT s� � � �7�7�>�>�$��G�$6�$6�t�$<�
��_�_�T�*� $�a�-�����=�#�$� $�=�$�
�$�
�� �W�/�/�0�
���
�s5 �A? �A3�A? �)A? �3A<�8A? �<A? �?B�Bc � � i } t j | � 5 }t j d� }|j � D �cg c] }|j |� s�|�� }}t
|� dk7 r
ddd� y|j |d � 5 }|j � D ]| }|j � }|j d� r�% |j d� \ }} |j d� j � }| j d� j � } | ||< |