o
    Û1jÑ  ã                   @   s2   d dl Z d dlmZmZmZ G dd„ deeƒZdS )é    N)ÚPluginÚIndependentPluginÚ	PluginOptc                   @   sX   e Zd ZdZd ZdZdZdZdZe	dde
dd	�e	d
de
dd	�e	dddd�gZdd„ ZdS )ÚInstructlabaL  
    This plugin is used to capture information about
    Instructlab installations.
    InstructLab is an open source project for enhancing
    large language models (LLMs) used in generative
    artificial intelligence (gen AI) applications.
    Instructlab can run either as a container, or directly
    outside a container.
    Úinstructlab)Úai)r   Úilab)r   ú	ilab-userz
cloud-userzuser that runs instructlab)ÚdefaultÚval_typeÚdescúilab-conf-dirÚ zinstructlab data directoryú	get-cacheFz#Capture models and osci cached data)r
   r   c              	      s  d}d}d}d}d}ˆ  ||¡}ˆ  ||¡}ˆ  ||¡‰ ˆ ˆ  ˆ d¡ˆ  ˆ d¡ˆ  |d¡ˆ  |d	¡g¡ g d
¢}g d¢}	zˆ d¡d d }
W n tyS   d }
Y nw ˆj|› d�|› d�g|
d� ˆj‡ ‡fdd„|	D ƒ|
d� ˆjdd„ |D ƒ|
d� ˆj|d|
d� ˆ d¡r“ˆj|› |
d� ˆ t	ˆj
ƒ¡ ˆ d¡}zt |¡}W n tyº   ˆ d|› d�¡ Y d S w |�r|j}ˆ d¡rÏˆ  |ˆ d¡¡}ˆ  ||¡‰ˆ ˆ  ||¡¡ ˆ ‡‡fdd„|	D ƒ¡ ˆjˆ  ||¡dd� ˆ d¡�r	ˆ ˆ  ||¡¡ d S d S d S )Nz/usr/share/instructlab/configz/opt/app-root/srcz.cache/instructlabz.config/instructlabz.local/share/instructlabztaxonomy/.gitztaxonomy/.githubz*src/.local/share/instructlab/taxonomy/.gitz-src/.local/share/instructlab/taxonomy/.github)ztaxonomy diffz#taxonomy diff --taxonomy-base=emptyzsystem infoz
model listzconfig show)	ÚdataÚ	generatedÚtaxonomyÚtaxonomy_dataÚchatlogsÚcheckpointsÚdatasetsÚinternalÚphasedzinstructlab*r   é   z/rhel_ai_config.yamlz/config.yaml)Ú	containerc                    ó   g | ]}ˆ  ˆ |¡‘qS © ©Ú	path_join©Ú.0Údata_dir)Úcont_local_pathÚselfr   ú@/usr/lib/python3/dist-packages/sos/report/plugins/instructlab.pyÚ
<listcomp>g   s    ÿz%Instructlab.setup.<locals>.<listcomp>c                 S   s   g | ]}d |› �‘qS )zilab r   )r    Úsubr   r   r$   r%   l   s    T)Ú	recursiver   r   r	   zUser "z›" does not exist, will not collect Instructlab information. Use `-k instructlab.ilab-user` option to define the user to use to collect data for Instructlabr   c                    r   r   r   r   )Údata_dirs_baser#   r   r$   r%   �   s    
ÿÿ)r'   )r   Úadd_forbidden_pathÚget_all_containers_by_regexÚ	ExceptionÚadd_copy_specÚadd_cmd_outputÚadd_dir_listingÚ
get_optionÚadd_container_logsÚlistÚ
containersÚpwdÚgetpwnamÚKeyErrorÚ	_log_warnÚpw_dir)r#   Úcont_share_conf_pathÚcont_opt_pathÚ	cache_dirÚ
config_dirÚlocal_share_dirÚcont_cache_pathÚcont_config_pathÚsubcmdsÚ	data_dirsÚilab_conÚ	ilab_userÚuser_pwdÚilab_dirr   )r"   r(   r#   r$   Úsetup)   s¨   ÿ
ÿÿú
ÿÿýÿýþý
þ

ÿù	

ÿþ
þ
ÿízInstructlab.setupN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú
short_descÚplugin_nameÚprofilesr2   Úcommandsr   ÚstrÚoption_listrE   r   r   r   r$   r      s$    
ÿÿÿû	r   )r3   Úsos.report.pluginsr   r   r   r   r   r   r   r$   Ú<module>   s   
