3 \ 2�@s�dZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z Gdd�d�Z dd �Z ejfd d �Zd d �Zddd�ZdS)zsdistutils.filelist Provides the FileList class, used for poking about the filesystem and building lists of files. �N)� convert_path)�DistutilsTemplateError�DistutilsInternalError)�logc@s|eZdZdZddd�Zdd�Zejfdd�Zd d �Z d d �Z d d�Z dd�Z dd�Z dd�Zdd�Zddd�Zddd�ZdS) �FileLista�A list of files built by on exploring the filesystem and filtered by applying various patterns to what we find there. Instance attributes: dir directory from which files will be taken -- only used if 'allfiles' not supplied to constructor files list of filenames currently being built/filtered/manipulated allfiles complete list of files under consideration (ie. without any filtering applied) NcCsd|_g|_dS)N)�allfiles�files)�self�warn� debug_print�r �*/usr/lib64/python3.6/distutils/filelist.py�__init__szFileList.__init__cCs ||_dS)N)r)r rr r r � set_allfiles#szFileList.set_allfilescCst|�|_dS)N)�findallr)r �dirr r r r&szFileList.findallcCsddlm}|rt|�dS)z~Print 'msg' to stdout if the global DEBUG (taken from the DISTUTILS_DEBUG environment variable) flag is true. r)�DEBUGN)Zdistutils.debugr�print)r �msgrr r r r )s zFileList.debug_printcCs|jj|�dS)N)r�append)r �itemr r r r3szFileList.appendcCs|jj|�dS)N)r�extend)r �itemsr r r r6szFileList.extendcCs@tttjj|j��}g|_x |D]}|jjtjj|��q WdS)N)�sorted�map�os�path�splitrr�join)r Zsortable_filesZ sort_tupler r r �sort9s z FileList.sortcCsDx>tt|j�ddd�D]$}|j||j|dkr|j|=qWdS)N�r�����)�range�lenr)r �ir r r �remove_duplicatesCszFileList.remove_duplicatescCs�|j�}|d}d}}}|dkrTt|�dkr ...cSsg|] }t|��qSr )r)�.0�wr r r � Wsz1FileList._parse_template_line..r �recursive-include�recursive-exclude�z,'%s' expects ...cSsg|] }t|��qSr )r)r+r,r r r r-]s�graft�prunez#'%s' expects a single zunknown action '%s')r&r'r(r))r.r/)r1r2)rr#rr)r �lineZwords�action�patternsr� dir_patternr r r �_parse_template_lineLs,         zFileList._parse_template_linecCsX|j|�\}}}}|dkrZ|jddj|��x&|D]}|j|dd�s4tjd|�q4W�n�|dkr�|jddj|��x&|D]}|j|dd�s|tjd |�q|W�n�|d kr�|jd dj|��x&|D]}|j|d d�s�tjd |�q�W�nj|dk�r8|jddj|��x*|D]"}|j|d d��stjd|��qW�n|dk�r�|jd|dj|�f�x,|D]$}|j||d��s`tjd||��q`Wn�|dk�r�|jd|dj|�f�x�|D]$}|j||d��s�tjd||��q�Wnx|dk�r|jd|�|jd|d��sTtjd|�nB|dk�rH|jd|�|jd|d��sTtjd|�n td|��dS)Nr&zinclude � r )�anchorz%warning: no files found matching '%s'r'zexclude z9warning: no previously-included files found matching '%s'zglobal-includezglobal-include rz>warning: no files found matching '%s' anywhere in distributionzglobal-excludezglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionzrecursive-includezrecursive-include %s %s)�prefixz:warning: no files found matching '%s' under directory '%s'zrecursive-excludezrecursive-exclude %s %szNwarning: no previously-included files matching '%s' found under directory '%s'r1zgraft z+warning: no directories found matching '%s'r2zprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s')r7r r�include_patternrr �exclude_patternr)r r3r4r5rr6�patternr r r �process_template_linehsf           zFileList.process_template_liner rcCspd}t||||�}|jd|j�|jdkr4|j�x6|jD],}|j|�r<|jd|�|jj|�d}qr;r<r r r r rs     L ,rcCs&dd�tj|dd�D�}ttjj|�S)z% Find all files under 'path' css,|]$\}}}|D]}tjj||�VqqdS)N)rrr)r+�base�dirsr�filer r r � �sz#_find_all_simple..T)� followlinks)r�walk�filterr�isfile)rZresultsr r r �_find_all_simple�srRcCs6t|�}|tjkr.tjtjj|d�}t||�}t|�S)z� Find all files under 'dir' and return the list of full filenames. Unless dir is '.', return full filenames with dir prepended. )�start) rRrrI� functools�partialr�relpathr�list)rrZmake_relr r r rs   rcCs8tj|�}tj}tjdkrd}d|}tjd||�}|S)z�Translate a shell-like glob pattern to a regular expression; return a string containing the regex. Differs from 'fnmatch.translate()' in that '*' does not match "special characters" (which are platform-specific). �\z\\\\z\1[^%s]z((?s  i