a „oe“5ã@s–dZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z Gdd„dƒZ d d „Z Gd d „d eƒZejfd d„Zdd„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ú?C:\Program Files\Certbot\pkgs\setuptools\_distutils\filelist.pyÚ__init__ szFileList.__init__cCs ||_dSr )r )r r rrrÚ set_allfiles&szFileList.set_allfilescCst|ƒ|_dSr )Úfindallr )r Údirrrrr)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 Úmsgrrrrr,s zFileList.debug_printcCs|j |¡dSr )r Úappend)r Úitemrrrr7szFileList.appendcCs|j |¡dSr )r Úextend)r Úitemsrrrr:szFileList.extendcCs<tttjj|jƒƒ}g|_|D]}|j tjj|Ž¡qdSr )ÚsortedÚmapÚosÚpathÚsplitr rÚjoin)r Zsortable_filesZ sort_tuplerrrÚsort=sz FileList.sortcCs@tt|jƒdddƒD]$}|j||j|dkr|j|=qdS)Nrréÿÿÿÿ)ÚrangeÚlenr )r ÚirrrÚremove_duplicatesFszFileList.remove_duplicatescCsÞ| ¡}|d}d}}}|dvrTt|ƒdkr ...cSsg|] }t|ƒ‘qSrr©Ú.0ÚwrrrÚ Yóz1FileList._parse_template_line..r)úrecursive-includeúrecursive-excludeéz,'%s' expects ...cSsg|] }t|ƒ‘qSrrr-rrrr0`r1)ÚgraftÚprunez#'%s' expects a single zunknown action '%s')r r%rr)r ÚlineÚwordsÚactionÚpatternsrÚ dir_patternrrrÚ_parse_template_lineNs0  ÿ ÿ  ÿ zFileList._parse_template_linecCsD| |¡\}}}}|dkrV| dd |¡¡|D]}|j|dd�s2t d|¡q2�nê|dkrš| dd |¡¡|D]}|j|dd�svt d |¡qv�n¦|d krÞ| d d |¡¡|D]}|j|d d�sºt d |¡qº�nb|dk�r(| dd |¡¡|D]"}|j|d d��st d|¡�q�n|dk�rz| d |d |¡¡¡|D](}|j||d��sNd}t |||¡�qNnÆ|dk�rÈ| d |d |¡¡¡|D]$}|j||d��s t d||¡�q nx|dk�rþ| d|¡|jd|d��s@t d|¡nB|dk�r4| d|¡|jd|d��s@t d|¡n td|ƒ‚dS)Nr(zinclude ú r)Úanchorz%warning: no files found matching '%s'r)zexclude z9warning: no previously-included files found matching '%s'r*zglobal-include rz>warning: no files found matching '%s' anywhere in distributionr+zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionr2zrecursive-include {} {})Úprefixz:warning: no files found matching '%s' under directory '%s'r3zrecursive-exclude {} {}zNwarning: no previously-included files matching '%s' found under directory '%s'r5zgraft z+warning: no directories found matching '%s'r6zprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s') r<rr!Úinclude_patternrZwarningÚexclude_patternÚformatr)r r7r9r:rr;ÚpatternrrrrÚprocess_template_linelsxû û  û  ÿ ú  þÿzFileList.process_template_linerrcCsld}t||||ƒ}| d|j¡|jdur4| ¡|jD],}| |¡r:| d|¡|j |¡d}q:|S)a—Select strings (presumably filenames) from 'self.files' that match 'pattern', a Unix-style wildcard (glob) pattern. Patterns are not quite the same as implemented by the 'fnmatch' module: '*' and '?' match non-special characters, where "special" is platform- dependent: slash on Unix; colon, slash, and backslash on DOS/Windows; and colon on Mac OS. If 'anchor' is true (the default), then the pattern match is more stringent: "*.py" will match "foo.py" but not "foo/bar.py". If 'anchor' is false, both of these will match. If 'prefix' is supplied, then only filenames starting with 'prefix' (itself a pattern) and ending with 'pattern', with anything in between them, will match. 'anchor' is ignored in this case. If 'is_regex' is true, 'anchor' and 'prefix' are ignored, and 'pattern' is assumed to be either a string containing a regex or a regex object -- no translation is done, the regex is just compiled and used as-is. Selected strings will be added to self.files. Return True if files are found, False otherwise. Fz%include_pattern: applying regex r'%s'Nz adding T)Útranslate_patternrrCr rÚsearchr r)r rCr>r?Úis_regexÚ files_foundÚ pattern_reÚnamerrrr@Ês    zFileList.include_patterncCsrd}t||||ƒ}| d|j¡tt|jƒdddƒD]4}| |j|¡r8| d|j|¡|j|=d}q8|S)aRemove strings (presumably filenames) from 'files' that match 'pattern'. Other parameters are the same as for 'include_pattern()', above. The list 'self.files' is modified in place. Return True if files are found, False otherwise. Fz%exclude_pattern: applying regex r'%s'rr#z removing T)rErrCr$r%r rF)r rCr>r?rGrHrIr&rrrrAószFileList.exclude_pattern)NN)rNr)rNr)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrÚcurdirrrrrr"r'r<rDr@rArrrrrs   ^ )rcCs0t tj|dd�¡}dd„|Dƒ}ttjj|ƒS)z% Find all files under 'path' T)Ú followlinkscss,|]$\}}}|D]}tj ||¡VqqdSr )rrr!)r.ÚbaseÚdirsr ÚfilerrrÚ sz#_find_all_simple..)Ú _UniqueDirsÚfilterrÚwalkrÚisfile)rZ all_uniqueÚresultsrrrÚ_find_all_simples ÿrZc@s$eZdZdZdd„Zedd„ƒZdS)rUz† Exclude previously-seen dirs from walk results, avoiding infinite recursion. Ref https://bugs.python.org/issue44497. cCsF|\}}}t |¡}|j|jf}||v}|r6|dd…=| |¡| S)z® Given an item from an os.walk result, determine if the item represents a unique dir for this instance and if not, prevent further traversal. N)rÚstatÚst_devÚst_inoÚadd)r Z walk_itemrQrRr r[Ú candidateÚfoundrrrÚ__call__s     z_UniqueDirs.__call__cCs t|ƒ|ƒSr )rV)ÚclsrrrrrV)sz_UniqueDirs.filterN)rKrLrMrNraÚ classmethodrVrrrrrUsrUcCs6t|ƒ}|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) rZrrOÚ functoolsÚpartialrÚrelpathrÚlist)rr Zmake_relrrrr.s   rcCs8t |¡}tj}tjdkrd}d|}t d||¡}|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((?r?rGrdrpÚendrIZ prefix_rerlrrrrEQs*   rE)rNr)rNrrmrjreÚutilrÚerrorsrrZ_logrrrZÚsetrUrOrrorErrrrÚs  x