o
    id                     @   sB   d dl mZmZ d dlZd dlZd dlmZ G dd deeZdS )    )PluginRedHatPluginN)Pathc                   @   s   e Zd ZdZdZdd ZdS )
UnpackagedzDCollects a list of files that are not handled by the package manager
unpackagedc           	         s   dd }dfdd	}fdd}j ddsd S d	A}| g }tfd
djjj D  D ]}|||7 }q9 fdd|D }||}|d| W d    d S 1 sbw   Y  d S )Nc                   S   s   t jd dS )z3Return a list of directories in $PATH.
            PATH:)osenvironsplit r   r   ?/usr/lib/python3/dist-packages/sos/report/plugins/unpackaged.pyget_env_path_list   s   z-Unpackaged.collect.<locals>.get_env_path_listc              
      s   g }t j| ddD ]d\}}}|r"|D ]  fdd|D |dd< q|D ]2}||} ztt | jr<t|  } W n	 t	yF   Y q$w |
||t j| g q$|D ]}||}|
|t j|g qYq	|S )zReturn a list of all files present on the system, excluding
                any directories listed in `exclude`.

            :param path: the starting path
            :param exclude: list of paths to exclude
            T)topdownc                    s   g | ]}| vr|qS r   r   ).0der   r   
<listcomp>)   s    z@Unpackaged.collect.<locals>.all_files_system.<locals>.<listcomp>N)r	   walk	path_joinstatS_ISLNKlstatst_moder   resolve	Exceptionappendpathrealpath)r   exclude	file_listrootdirsfilesnameselfr   r   all_files_system   s,   z,Unpackaged.collect.<locals>.all_files_systemc                    sx   g }| D ]5}  |}| }d} |r2|dk r2t|}|d| 7 }|d7 } |r2|dk s||d  q|S )z4Format the unpackaged list as a string.
            r   
   z ->    
)r   path_islinkr	   readlinkr   )r$   expandedffpoutlinksr&   r   r   format_output:   s   

z)Unpackaged.collect.<locals>.format_outputT)cmdr   c                 3   s2    | ] t  fd dD rtj V  qdS )c                    s   g | ]}  |qS r   )
startswith)r   pxr   r   r   W   s    z0Unpackaged.collect.<locals>.<genexpr>.<listcomp>N)anyr	   r   r   )r   )pathsr7   r   	<genexpr>T   s    

z%Unpackaged.collect.<locals>.<genexpr>c                    s   g | ]
\}}| vr|qS r   r   )r   r8   rp)all_frpmr   r   r   \   s    z&Unpackaged.collect.<locals>.<listcomp> )N)	test_predicatecollection_filesetpolicymangle_package_pathpackage_manager	all_fileswritejoin)	r'   r   r(   r3   ufileall_fsystemr   not_packagednot_packaged_expandedr   )r=   r:   r'   r   collect   s&   
"zUnpackaged.collectN)__name__
__module____qualname__
short_descplugin_namerL   r   r   r   r   r      s    r   )sos.report.pluginsr   r   r	   r   pathlibr   r   r   r   r   r   <module>   s
   