î Ôê[°1ã@sªdZddlZddlZddlZddlmZddlmZmZddl m Z Gdd„dƒZ ej dd „Z d d „Zd ddd d„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ÄeZdZdZdddd„Zdd„Zejdd„Zd d „Z d d „Z d d„Z dd„Z dd„Z dd„Zdd„Zddddd„Zddddd„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/lib/python3.4/distutils/filelist.pyÚ__init__s zFileList.__init__cCs ||_dS)N)r)r rr r r Ú set_allfiles"szFileList.set_allfilescCst|ƒ|_dS)N)Úfindallr)r Údirr r r r%szFileList.findallcCs'ddlm}|r#t|ƒndS)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 (szFileList.debug_printcCs|jj|ƒdS)N)rÚappend)r Úitemr r r r2szFileList.appendcCs|jj|ƒdS)N)rÚextend)r Úitemsr r r r5szFileList.extendcCsXtttjj|jƒƒ}g|_x*|D]"}|jjtjj|Œƒq.WdS)N)ÚsortedÚmapÚosÚpathÚsplitrrÚjoin)r Zsortable_filesZ sort_tupler r r Úsort8s  z FileList.sortcCsYxRtt|jƒdddƒD]1}|j||j|dkr |j|=q q WdS)Néréÿÿÿÿ)ÚrangeÚlenr)r Úir r r Úremove_duplicatesBs&zFileList.remove_duplicatescCs:|jƒ}|d}d}}}|dkrut|ƒdkrUtd|ƒ‚ndd „|d d…Dƒ}nµ|dkrÖt|ƒd kr¦td|ƒ‚nt|d ƒ}dd „|dd…Dƒ}nT|dkrt|ƒdkrtd|ƒ‚nt|d ƒ}ntd|ƒ‚||||fS)NrÚincludeÚexcludeúglobal-includeúglobal-excludeéz&'%s' expects ...cSsg|]}t|ƒ‘qSr )r)Ú.0Úwr r r ú Vs z1FileList._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_lineKs,       zFileList._parse_template_linecCs|j|ƒ\}}}}|dkr}|jddj|ƒƒxÕ|D].}|j|ddƒsHtjd|ƒqHqHWnœ|dkrß|jddj|ƒƒxs|D].}|j|ddƒsªtjd |ƒqªqªWn:|d krA|jd dj|ƒƒx|D].}|j|dd ƒs tjd |ƒq q WnØ|dkr£|jddj|ƒƒx¯|D].}|j|dd ƒsntjd|ƒqnqnWnv|dkr|jd|dj|ƒfƒxG|D]1}|j|d|ƒsÖtjd||ƒqÖqÖWn |dkry|jd|dj|ƒfƒxÜ|D]1}|j|d|ƒsAtjd||ƒqAqAWn |dkrÁ|jd|ƒ|jdd|ƒstjd|ƒqnX|dkr |jd|ƒ|jdd|ƒstjd|ƒqntd|ƒ‚dS)Nr&zinclude ú Úanchorr z%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_linegsf                          zFileList.process_template_liner rcCsœd}t||||ƒ}|jd|jƒ|jdkrK|jƒnxJ|jD]?}|j|ƒrU|jd|ƒ|jj|ƒd}qUqUW|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_patternr r=rrÚsearchrr)r r=r9r:Úis_regexÚ files_foundÚ pattern_reÚnamer r r r;³s    zFileList.include_patterncCsžd}t||||ƒ}|jd|jƒxhtt|jƒdddƒD]G}|j|j|ƒrO|jd|j|ƒ|j|=d}qOqOW|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'r z removing Tr!r!)r?r r=r"r#rr@)r r=r9r:rArBrCr$r r r r<Þs  &  zFileList.exclude_pattern)Ú__name__Ú __module__Ú __qualname__Ú__doc__rrrÚcurdirrr rrrr%r7r>r;r<r r r r r s      L,rcCsddlm}m}m}m}g}|g}|j}|j}x»|r|ƒ}tj|ƒ} x–| D]Ž} |tj kr˜tj j || ƒ} n| } tj| ƒ} | |} || ƒrÓ|j| ƒqk|| ƒrk|| ƒ rk|| ƒqkqkWqFW|S)z^Find all files under 'dir' and return the list of full filenames (relative to 'dir'). r)ÚST_MODEÚS_ISREGÚS_ISDIRÚS_ISLNK) ÚstatrJrKrLrMÚpoprrÚlistdirrIrr)rrJrKrLrMÚlistÚstackrOÚpushÚnamesrDÚfullnamerNÚmoder r r rõs&"        rcCsStj|ƒ}tj}tjdkr0d}nd|}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((?t|ƒ}nd}|dk rºtdƒ}t|ƒdt|ƒ …}tj}tjdkršd}nd|j|d|fƒ}n|rÍd|}ntj|ƒS)aTranslate a shell-like wildcard pattern to a compiled regular expression. Return the compiled regex. If 'is_regex' true, then 'pattern' is directly compiled to a regex (if it's a string) or just returned as-is (assumes it's a regex object). ÚNrWz\\ú^z.*) Ú isinstanceÚstrr[Úcompiler]r#rrZr)r=r9r:rArCZ empty_patternZ prefix_rerZr r r r?+s"       r?)rHrr[rXZdistutils.utilrZdistutils.errorsrrZ distutilsrrrIrr]r?r r r r Ús è