ðÕYfæ0ã@sÂdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z Gdd„dƒZ dd „Z ejd d „Zd d „Zddddd„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 ú7/opt/alt/python35/lib64/python3.5/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|ƒ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 )szFileList.debug_printcCs|jj|ƒdS)N)rÚappend)r Úitemr r r r3szFileList.appendcCs|jj|ƒdS)N)rÚextend)r Úitemsr r r r6szFileList.extendcCsXtttjj|jƒƒ}g|_x*|D]"}|jjtjj|Œƒq.WdS)N)ÚsortedÚmapÚosÚpathÚsplitrrÚjoin)r Zsortable_filesZ sort_tupler r r Úsort9s  z FileList.sortcCsVxOtt|jƒdddƒD].}|j||j|dkr |j|=q WdS)Néréÿÿÿÿ)ÚrangeÚlenr)r Úir r r Úremove_duplicatesCs&zFileList.remove_duplicatescCs1|jƒ}|d}d}}}|dkrrt|ƒdkrRtd|ƒ‚dd „|d d…Dƒ}n¯|dkrÐt|ƒd kr td|ƒ‚t|d ƒ}dd „|dd…Dƒ}nQ|dkrt|ƒdkrþtd|ƒ‚t|d ƒ}ntd|ƒ‚||||fS)NrÚincludeÚexcludeúglobal-includeúglobal-excludeéz&'%s' expects ...cSsg|]}t|ƒ‘qSr )r)Ú.0Úwr r r ú Ws 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_lineLs,          zFileList._parse_template_linecCs|j|ƒ\}}}}|dkrz|jddj|ƒƒx½|D]+}|j|ddƒsHtjd|ƒqHWn‡|dkrÙ|jddj|ƒƒx^|D]+}|j|ddƒs§tjd |ƒq§Wn(|d kr8|jd dj|ƒƒxÿ|D]+}|j|dd ƒstjd |ƒqWnÉ|dkr—|jddj|ƒƒx |D]+}|j|dd ƒsetjd|ƒqeWnj|dkrÿ|jd|dj|ƒfƒx;|D].}|j|d|ƒsÊtjd||ƒqÊWn|dkrg|jd|dj|ƒfƒxÓ|D].}|j|d|ƒs2tjd||ƒq2Wnš|dkr¬|jd|ƒ|jdd|ƒstjd|ƒnU|dkrñ|jd|ƒ|jdd|ƒstjd|ƒntd|ƒ‚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_linehsf                          zFileList.process_template_liner rcCs–d}t||||ƒ}|jd|jƒ|jdkrH|jƒxG|jD]<}|j|ƒrR|jd|ƒ|jj|ƒd}qRW|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ƒxett|jƒdddƒD]D}|j|j|ƒrO|jd|j|ƒ|j|=d}qOW|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 rs      L,rcCs5dd„tj|ddƒDƒ}ttjj|ƒS)z% Find all files under 'path' css:|]0\}}}|D]}tjj||ƒVqqdS)N)rrr)r+ÚbaseÚdirsrÚfiler r r ú ûs z#_find_all_simple..Ú followlinksT)rÚwalkÚfilterrÚisfile)rZresultsr r r Ú_find_all_simpleös rRcCsOt|ƒ}|tjkrEtjtjjd|ƒ}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  rcCsPtj|ƒ}tj}tjdkr-d}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  è