mò &U²Ic@s²dZdZdkZdkZdkZdkZdkTdklZdkl Z dk l Z l Z dk lZdfd „ƒYZeid „Zd „Zd ed d„ZdS(ssdistutils.filelist Provides the FileList class, used for poking about the filesystem and building lists of files. s4$Id: filelist.py 37828 2004-11-10 22:23:15Z loewis $N(t*(sglob(s convert_path(sDistutilsTemplateErrorsDistutilsInternalError(slogtFileListcBs˜tZdZeed„Zd„Zeid„Zd„Z d„Z d„Z d„Z d„Z d „Zd „Zd ed d „Zd ed d„ZRS(sÑ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) cCsd|_g|_dS(N(tNonetselftallfilestfiles(Rtwarnt debug_print((t//data/zmath/lib/python2.4/distutils/filelist.pyt__init__#s cCs ||_dS(N(RR(RR((Rt set_allfiles,scCst|ƒ|_dS(N(tfindalltdirRR(RR ((RR /scCs!dkl}|o |GHndS(s~Print 'msg' to stdout if the global DEBUG (taken from the DISTUTILS_DEBUG environment variable) flag is true. (sDEBUGN(tdistutils.debugtDEBUGtmsg(RRR((RR2s cCs|ii|ƒdS(N(RRtappendtitem(RR((RR<scCs|ii|ƒdS(N(RRtextendtitems(RR((RR?scCs_ttii|iƒ}|iƒg|_x-|D]%}|ii t tii |ƒƒq2WdS(N( tmaptostpathtsplitRRtsortable_filestsortt sort_tupleRtapplytjoin(RRR((RRBs   cCs[xTtt|iƒdddƒD]3}|i||i|djo|i|=q q WdS(Niiiÿÿÿÿ(trangetlenRRti(RR((Rtremove_duplicatesMs cCs)ti|ƒ}|d}d}}}|djo;t |ƒdjot d|‚nt t |dƒ}n«|djoKt |ƒd jot d |‚nt |dƒ}t t |dƒ}nS|djo8t |ƒdjot d|‚nt |dƒ}nt d|‚||||fS(Nitincludetexcludesglobal-includesglobal-excludeis&'%s' expects ...isrecursive-includesrecursive-excludeis,'%s' expects ...tgrafttprunes#'%s' expects a single sunknown action '%s'(R!R"sglobal-includesglobal-exclude(srecursive-includesrecursive-exclude(R#R$( tstringRtlinetwordstactionRtpatternsR t dir_patternRtDistutilsTemplateErrorRt convert_path(RR&R)R'R(R*R ((Rt_parse_template_lineVs$     cCsF|i|ƒ\}}}}|djoY|idti |ƒƒxý|D]0}|i |ddƒpt i d|ƒqIqIWnÂ|djoY|idti |ƒƒx—|D]0}|i|ddƒpt i d|ƒq¯q¯Wn\|d jo]|id ti |ƒƒx1|D]4}|i |dd ƒpt i d d |ƒqqWnò|djoY|idti |ƒƒxÇ|D]0}|i|dd ƒpt i d|ƒqqWnŒ|djof|id|ti |ƒfƒx[|D]7}|i |d|ƒpt i d d||ƒqëqëWn|djob|id|ti |ƒfƒxè|D]3}|i|d|ƒpt i d||ƒq^q^Wnª|djo?|id|ƒ|i dd|ƒpt i d|ƒqBn^|djoC|id|ƒ|idd|ƒpt i dd|ƒqBntd|‚dS( NR!sinclude tanchoris%warning: no files found matching '%s'R"sexclude s9warning: no previously-included files found matching '%s'sglobal-includesglobal-include is&warning: no files found matching '%s' sanywhere in distributionsglobal-excludesglobal-exclude sRwarning: no previously-included files matching '%s' found anywhere in distributionsrecursive-includesrecursive-include %s %stprefixsunder directory '%s'srecursive-excludesrecursive-exclude %s %ssNwarning: no previously-included files matching '%s' found under directory '%s'R#sgraft s+warning: no directories found matching '%s'R$sprune s)no previously-included directories found s matching '%s's'this cannot happen: invalid action '%s'(RR-R&R(R)R R*RR%Rtpatterntinclude_patterntlogRtexclude_patternRtDistutilsInternalError(RR&R0R)R(R*R ((Rtprocess_template_line{sl                  iicCs d}t||||ƒ}|id|iƒ|i djo|i ƒnxL|i D]A}|i |ƒo+|id|ƒ|ii|ƒd}qWqWW|S(sƒ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 1 if files are found. is%include_pattern: applying regex r'%s's adding iN(t files_foundttranslate_patternR0R.R/tis_regext pattern_reRRRRR tnametsearchRR(RR0R.R/R8R:R6R9((RR1Ês cCs d}t||||ƒ}|id|iƒxjt t |i ƒdddƒD]I}|i |i |ƒo,|id|i |ƒ|i |=d}qOqOW|S(süRemove 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 1 if files are found. is%exclude_pattern: applying regex r'%s'iiÿÿÿÿs removing N(R6R7R0R.R/R8R9RRRRRRR;(RR0R.R/R8R6R9R((RR3øs  (t__name__t __module__t__doc__RR R RtcurdirR RRRRR R-R5R1R3(((RRs     % O.cCs dkl}l}l} l} g}|g} | i}| i }xÄ| o¼|ƒ}t i |ƒ} x| D]•}|t ijot ii||ƒ} n|} t i| ƒ}||}||ƒo|i | ƒqi| |ƒo| |ƒ o|| ƒqiqiWqCW|S(s^Find all files under 'dir' and return the list of full filenames (relative to 'dir'). (sST_MODEsS_ISREGsS_ISDIRsS_ISLNKN(tstattST_MODEtS_ISREGtS_ISDIRtS_ISLNKtlistR tstacktpopRtpushRtlistdirtnamesR:R?RRtfullnametmode(R R@R:RBRERARLRHRGRCRKRDRFRJ((RR s,      cCs(ti|ƒ}tidd|ƒ}|S(sæ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). s (^|[^\\])\.s\1[^/]N(tfnmatcht translateR0R9tretsub(R0R9((Rt glob_to_re4s iicCs³|o,t|ƒtjoti|ƒSq3|Sn|ot|ƒ}nd}|dj o4t|ƒdd!}dt i i |d|ƒ}n|od|}nti|ƒS(sTranslate 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). tiiÿÿÿÿt^s.*N(R8ttypeR0t StringTypeROtcompileRQR9R/Rt prefix_reRRRR.(R0R.R/R8R9RW((RR7Is !(R>t __revision__RR%RORMttypestglobtdistutils.utilR,tdistutils.errorsR+R4t distutilsR2RR?R RQRR7(R,RXR%RQRZR4RR+R7RORMRR R2((Rt?s    ÿ