ó \Z-Lc@sÔddlmZddlZddlmZddlZddlZddlmZejdƒd„Zd„Z d„Z d „Z d dd „ƒYZ d dd „ƒYZ ddd„ƒYZddd„ƒYZdS(iÿÿÿÿ(tglobN(tlistdir(tmktemps ([\$\^\*\+\.\?\{\}\[\]\(\)\|\\])cCs|jd|ƒS(Ns\\\1(tsub(ttxttescapeRE((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt_escapeRegexChars scOst||ŽjƒS(sºRecursively find all the files matching a glob pattern. This function is a wrapper around the FileFinder class. See its docstring for details about the accepted arguments, etc.(t FileFindertfiles(targstkw((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt findFiles scCs"t|ƒ}t|||ƒjƒS(s/Replace all instances of 'theStr' with 'repl' for each file in the 'files' list. Returns a dictionary with data about the matches found. This is like string.replace() on a multi-file basis. This function is a wrapper around the FindAndReplace class. See its docstring for more details.(RtFindAndReplacetresults(RttheStrtrepltpattern((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytreplaceStrInFiless cCst|||ƒjƒS(s,Replace all instances of regex 'pattern' with 'repl' for each file in the 'files' list. Returns a dictionary with data about the matches found. This is like re.sub on a multi-file basis. This function is a wrapper around the FindAndReplace class. See its docstring for more details.(R R (RRR((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytreplaceRegexInFiles"s RcBsbeZdZd d d d„Zdejejjejjd„Z d„Z e d„Z d „Z RS( sgTraverses a directory tree and finds all files in it that match one of the specified glob patterns.t*tCVSs.svncCs>||_||_||_||_g|_|j|ƒdS(N(t _rootPatht _globPatternst_ignoreBasenamest _ignoreDirst_filest walkDirTree(tselftrootPatht globPatternstignoreBasenamest ignoreDirs((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt__init__7s      t.c Cs¢|j}|j}|g}|j}|j} xn|r| ƒ}||ƒxN||ƒD]@} ||| ƒ} || ƒrV|| | ƒr–|| ƒq–qVqVWq0WdS(sBRecursively walk through a directory tree and find matching files.N(t processDirt filterDirtappendtpop( RtdirRtisdirtjoinR"R#t pendingDirstaddDirtgetDirtbaseNametfullPath((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyREs         cCs||jkp||jk S(s'A hook for filtering out certain dirs. (RR(RR,R-((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR#`scCsC|jj}x0|jD]%}||tjj||ƒƒƒqWdS(N(RtextendRtostpathR((RR&RR.R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR"gs cCs|jS(N(R(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRls(R(sCVSs.svn((t__name__t __module__t__doc__R R/RR0R'R(RR#RR"R(((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR2s    t_GenSubberFunccBsÝeZdZejdƒZejdƒZd„Zd„Zd„Z d„Z d„Z dd „Z dd „Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(s³Converts a 'sub' string in the form that one feeds to re.sub (backrefs, groups, etc.) into a function that can be used to do the substitutions in the FindAndReplace class.s\\([1-9][0-9]*)s\\g<([a-zA-Z_][a-zA-Z_]*)>cCs)||_d|_g|_|jƒdS(Ni(t_srct_post _codeChunkstparse(Rt replaceStr((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR xs   cCs|jS(N(R5(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytsrc~scCs|jS(N(R6(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytposscCs ||_dS(N(R6(RR;((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytsetPos„scCs|jt|jƒkS(N(R6tlenR5(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytatEnd‡sicCs|j|7_dS(N(R6(Rtoffset((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytadvanceŠscCsJ|dkr|j}n||_|jƒr8|j|S|j||!SdS(N(tNoneR6R>R5(Rttotstart((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytreadTos      cCs|jj|jƒ|jƒƒS(N(t backrefREtmatchR:R;(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt matchBackref˜scCs,|jƒ}|j|jƒƒ|jdƒS(Ni(RGR<tendtgroup(Rtm((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt getBackref›s cCs|jj|jƒ|jƒƒS(N(tgroupRERFR:R;(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt matchGroup scCs,|jƒ}|j|jƒƒ|jdƒS(Ni(RMR<RHRI(RRJ((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytgetGroup£s cCsSxL|jƒsN|jƒr(|jƒq|jƒrA|jƒq|jƒqWdS(N(R>RGt eatBackrefRMteatGroupt eatStrConst(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR8ªs     cCsw|jƒ}x6|jƒsD|jƒs3|jƒr7Pq|jƒqW|j|jƒd|ƒ}|jt|ƒƒdS(NRC(R;R>RGRMR@RDtaddChunktrepr(RtstartPoststrConst((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRQ³s cCs|jd|jƒdƒdS(Nsm.group(t)(RRRK(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRO½scCs|jd|jƒdƒdS(Ns m.group("s")(RRRN(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRPÀscCs|jj|ƒdS(N(R7R$(Rtchunk((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRRÃscCsdj|jƒS(Ns, (R(R7(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytcodeBodyÈscCsd|jƒS(Ns%def subber(m): return ''.join([%s]) (RX(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytcodeËscBs|jƒdUeS(N(RYtsubber(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt subberFuncÎsN(R1R2R3tretcompileRERLR R:R;R<R>R@RARDRGRKRMRNR8RQRORPRRRXRYR[(((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR4os,               R cBs5eZdZed„Zd„Zd„Zd„ZRS(s`Find and replace all instances of 'patternOrRE' with 'replacement' for each file in the 'files' list. This is a multi-file version of re.sub(). 'patternOrRE' can be a raw regex pattern or a regex object as generated by the re module. 'replacement' can be any string that would work with patternOrRE.sub(replacement, fileContents). cCs$t|tƒr$tj|ƒ|_n ||_t|tƒrTt|ƒjƒ|_n ||_|jj|_ }||_ i|_ ||_ t |_tjdƒdjƒjdƒrtƒ}t|dƒjdƒtjd|d|ƒdjƒst|_ntj|ƒn|jƒdS(NtpgrepisUsage:twt#spgrep "s" (t isinstancet basestringR\R]t_regexR4R[t_subberRt_patternRt_resultst_recordResultstFalset _usePgrepR/tpopen3treadt startswithRtopentwritetTruetremovet_run(RRt patternOrREt replacementt recordResultsRttmpFile((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR Ýs$      " % cCs|jS(N(Rf(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR üsc Cs-|j}|j}|j}|j}x|jD]÷}tjj|ƒsLq.n||_t }dt ƒkrp~n|jr¦tj d|d|ƒj ƒrÐt }qÐn*t|ƒj ƒ}|j|ƒrÐt }n|r.dt ƒkrút|ƒj ƒ}n|j||ƒ}t|dƒj|ƒq.q.WdS(Ntorigspgrep "s" R_(Rct_subDispatcherRiReRR/R0tisfilet _currFileRhtlocalstpopenRkRoRmtsearchRRn( RtregexRZtusePgrepRtfiletfoundRvtnew((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRqÿs,      !  cCs®|jr¡|j|jkrFi}|j|j/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRws    (R1R2R3RoR R RqRw(((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR Ós    tSourceFileStatscBsAeZdZdZd„Zd„Zd„Zd„Zd„Z RS(s cCs5i|_}x!|D]}|j|ƒ||/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR 1s  cCs|jS(N(R‡(R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytrawStats6scCs“d}d}d}d}xR|jƒjƒD]>}||d7}||d7}||d7}||d7}q+Wi|d6|d6|d6|d6}|S(Nit codeLinest blankLinest commentLinest totalLines(RŠtvalues(RR‹RŒRRŽt fileStatsR‰((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pytsummary9s  cCsdS(N((R((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyt printStatsKsc CsÍd}d}d}tjdƒ}tjdƒ}t|ƒjƒjƒ}t|ƒ}xP|D]H} |j| ƒr}|d7}q[|j| ƒr™|d7}q[|d7}q[Wi|d6|d6|d6|d6} | S( Nis\s#.*$s\s$iR‹RŒRRŽ(R\R]RmRkt splitlinesR=RF( RtfileNameR‹RŒRt commentLineRet blankLineRetlinesRŽtlineR‰((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyRˆNs$      N( R1R2R3RAR‡R RŠR‘R’Rˆ(((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyR†*s    (((((RR/Rtos.pathR\ttempfileRR]RR RRRR4R R†(((s>/opt/freeware/lib/python2.7/site-packages/Cheetah/FileUtils.pyts     =dW