a
    ´i 2  ã                   @   s‚   d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
 G dd„ dƒZdd„ Ze jfd	d
„Zdd„ Zddd„ZdS )é    N©Úconvert_path)ÚDistutilsTemplateErrorÚDistutilsInternalError)Úlogc                   @   sx   e Zd Zddd„Zdd„ Zejfdd„Zdd	„ Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zddd„Zddd„ZdS )ÚFileListNc                 C   s   d | _ g | _d S ©N)ÚallfilesÚfiles)ÚselfÚwarnÚdebug_print© r   ú*/usr/lib64/python3.9/distutils/filelist.pyÚ__init__   s    zFileList.__init__c                 C   s
   || _ d S r   )r	   )r   r	   r   r   r   Úset_allfiles#   s    zFileList.set_allfilesc                 C   s   t |ƒ| _d S r   )Úfindallr	   )r   Údirr   r   r   r   &   s    zFileList.findallc                 C   s   ddl m} |rt|ƒ d S )Nr   )ÚDEBUG)Zdistutils.debugr   Úprint)r   Úmsgr   r   r   r   r   )   s    zFileList.debug_printc                 C   s   | j  |¡ d S r   )r
   Úappend)r   Úitemr   r   r   r   3   s    zFileList.appendc                 C   s   | j  |¡ d S r   )r
   Úextend)r   Úitemsr   r   r   r   6   s    zFileList.extendc                 C   s<   t ttjj| jƒƒ}g | _|D ]}| j tjj|Ž ¡ qd S r   )ÚsortedÚmapÚosÚpathÚsplitr
   r   Újoin)r   Zsortable_filesZ
sort_tupler   r   r   Úsort9   s    zFileList.sortc                 C   s@   t t| jƒd ddƒD ]$}| j| | j|d  kr| j|= qd S )Né   r   éÿÿÿÿ)ÚrangeÚlenr
   )r   Úir   r   r   Úremove_duplicatesC   s    zFileList.remove_duplicatesc                 C   sÞ   |  ¡ }|d }d  } }}|dv rTt|ƒdk r<td| ƒ‚dd„ |dd … D ƒ}n~|dv r˜t|ƒd	k rttd
| ƒ‚t|d ƒ}dd„ |dd … D ƒ}n:|dv rÆt|ƒdkr¸td| ƒ‚t|d ƒ}ntd| ƒ‚||||fS )Nr   )ÚincludeÚexcludeúglobal-includeúglobal-excludeé   z&'%s' expects <pattern1> <pattern2> ...c                 S   s   g | ]}t |ƒ‘qS r   r   ©Ú.0Úwr   r   r   Ú
<listcomp>W   ó    z1FileList._parse_template_line.<locals>.<listcomp>r"   )úrecursive-includeúrecursive-excludeé   z,'%s' expects <dir> <pattern1> <pattern2> ...c                 S   s   g | ]}t |ƒ‘qS r   r   r-   r   r   r   r0   ]   r1   )ÚgraftÚprunez#'%s' expects a single <dir_pattern>zunknown action '%s')r   r%   r   r   )r   ÚlineÚwordsÚactionÚpatternsr   Údir_patternr   r   r   Ú_parse_template_lineL   s0    ÿÿÿzFileList._parse_template_linec                 C   s@  |   |¡\}}}}|dkrV|  dd |¡ ¡ |D ]}| j|dd�s2t d|¡ q2�næ|dkrš|  dd |¡ ¡ |D ]}| j|dd�svt d	|¡ qv�n¢|d
krÞ|  dd |¡ ¡ |D ]}| j|dd�sºt d|¡ qº�n^|dk�r(|  dd |¡ ¡ |D ]"}| j|dd��s t d|¡ �q �n|dk�rv|  d|d |¡f ¡ |D ]$}| j||d��sNt d||¡ �qNnÆ|dk�rÄ|  d|d |¡f ¡ |D ]$}| j||d��sœt d||¡ �qœnx|dk�rú|  d| ¡ | jd |d��s<t d|¡ nB|dk�r0|  d| ¡ | jd |d��s<t d|¡ ntd| ƒ‚d S )Nr(   zinclude ú r"   )Úanchorz%warning: no files found matching '%s'r)   zexclude z9warning: no previously-included files found matching '%s'r*   zglobal-include r   z>warning: no files found matching '%s' anywhere in distributionr+   zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionr2   zrecursive-include %s %s)Úprefixz:warning: no files found matching '%s' under directory '%s'r3   zrecursive-exclude %s %szNwarning: no previously-included files matching '%s' found under directory '%s'r5   zgraft z+warning: no directories found matching '%s'r6   zprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s')r<   r   r    Úinclude_patternr   r   Úexclude_patternr   )r   r7   r9   r:   r   r;   Úpatternr   r   r   Úprocess_template_lineh   s|    ÿ
ÿ
ÿ

þ
ÿþ

ÿþ

ÿ
ÿÿzFileList.process_template_liner"   r   c                 C   sl   d}t ||||ƒ}|  d|j ¡ | jd u r4|  ¡  | jD ],}| |¡r:|  d| ¡ | j |¡ d}q:|S )NFz%include_pattern: applying regex r'%s'z adding T)Útranslate_patternr   rB   r	   r   Úsearchr
   r   )r   rB   r>   r?   Úis_regexÚfiles_foundÚ
pattern_reÚnamer   r   r   r@   ´   s    ÿ


zFileList.include_patternc                 C   sr   d}t ||||ƒ}|  d|j ¡ tt| jƒd ddƒD ]4}| | j| ¡r8|  d| j|  ¡ | j|= d}q8|S )NFz%exclude_pattern: applying regex r'%s'r"   r#   z
 removing T)rD   r   rB   r$   r%   r
   rE   )r   rB   r>   r?   rF   rG   rH   r&   r   r   r   rA   ß   s    ÿzFileList.exclude_pattern)NN)r"   Nr   )r"   Nr   )Ú__name__Ú
__module__Ú__qualname__r   r   r   Úcurdirr   r   r   r   r!   r'   r<   rC   r@   rA   r   r   r   r   r      s   


	L
, ÿr   c                 C   s&   dd„ t j| dd�D ƒ}tt jj|ƒS )Nc                 s   s,   | ]$\}}}|D ]}t j ||¡V  qqd S r   )r   r   r    )r.   ÚbaseÚdirsr
   Úfiler   r   r   Ú	<genexpr>ú   s   þz#_find_all_simple.<locals>.<genexpr>T)Úfollowlinks)r   ÚwalkÚfilterr   Úisfile)r   Úresultsr   r   r   Ú_find_all_simpleö   s    þrW   c                 C   s6   t | ƒ}| tjkr.tjtjj| d�}t||ƒ}t|ƒS )N)Ústart)	rW   r   rM   Ú	functoolsÚpartialr   Úrelpathr   Úlist)r   r
   Zmake_relr   r   r   r     s
    

r   c                 C   s8   t  | ¡}tj}tjdkrd}d| }t d||¡}|S )Nú\z\\\\z\1[^%s]z((?<!\\)(\\\\)*)\.)ÚfnmatchÚ	translater   ÚsepÚreÚsub)rB   rH   r`   Úescapedr   r   r   Ú
glob_to_re  s    

rd   r"   c           
      C   sØ   |rt | tƒrt | ¡S | S tdƒ d¡\}}}| r>t| ƒ}nd}|d ur²t|ƒ}|t|ƒt|ƒt|ƒ … }tj}	tjdkr‚d}	|t|ƒt|ƒt|ƒ … }d|||	||f }n|rÎd||t|ƒd … f }t |¡S )NÚ_Ú r]   z\\z%s\A%s%s.*%s%sz%s\A%s)	Ú
isinstanceÚstrra   Úcompilerd   Ú	partitionr%   r   r`   )
rB   r>   r?   rF   rX   re   ÚendrH   Z	prefix_rer`   r   r   r   rD   %  s(    


rD   )r"   Nr   )r   ra   r^   rY   Zdistutils.utilr   Zdistutils.errorsr   r   Z	distutilsr   r   rW   rM   r   rd   rD   r   r   r   r   Ú<module>   s    i