/
usr
/
lib64
/
python2.6
/
site-packages
/
Cheetah
/
/usr/lib64/python2.6/site-packages/Cheetah
mkdir
upload
Name
Size
Mode
Actions
Macros/
-
0755
rm
Templates/
-
0755
rm
Tests/
-
0755
rm
Tools/
-
0755
rm
Utils/
-
0755
rm
CacheRegion.py
4421
0644
edit
dl
rm
CacheRegion.pyc
6636
0644
edit
dl
rm
CacheRegion.pyo
6593
0644
edit
dl
rm
CacheStore.py
3047
0644
edit
dl
rm
CacheStore.pyc
5875
0644
edit
dl
rm
CacheStore.pyo
5875
0644
edit
dl
rm
CheetahWrapper.py
23885
0644
edit
dl
rm
CheetahWrapper.pyc
22958
0644
edit
dl
rm
CheetahWrapper.pyo
22895
0644
edit
dl
rm
Compiler.py
80284
0644
edit
dl
rm
Compiler.pyc
76754
0644
edit
dl
rm
Compiler.pyo
76680
0644
edit
dl
rm
convertTmplPathToModuleName.py
496
0644
edit
dl
rm
convertTmplPathToModuleName.pyc
706
0644
edit
dl
rm
convertTmplPathToModuleName.pyo
706
0644
edit
dl
rm
DirectiveAnalyzer.py
2445
0644
edit
dl
rm
DirectiveAnalyzer.pyc
4043
0644
edit
dl
rm
DirectiveAnalyzer.pyo
4043
0644
edit
dl
rm
Django.py
592
0644
edit
dl
rm
Django.pyc
945
0644
edit
dl
rm
Django.pyo
945
0644
edit
dl
rm
DummyTransaction.py
3277
0644
edit
dl
rm
DummyTransaction.pyc
5672
0644
edit
dl
rm
DummyTransaction.pyo
5672
0644
edit
dl
rm
ErrorCatchers.py
1755
0644
edit
dl
rm
ErrorCatchers.pyc
3610
0644
edit
dl
rm
ErrorCatchers.pyo
3610
0644
edit
dl
rm
FileUtils.py
10664
0644
edit
dl
rm
FileUtils.pyc
13455
0644
edit
dl
rm
FileUtils.pyo
13455
0644
edit
dl
rm
Filters.py
7639
0644
edit
dl
rm
Filters.pyc
8675
0644
edit
dl
rm
Filters.pyo
8675
0644
edit
dl
rm
ImportHooks.py
4476
0644
edit
dl
rm
ImportHooks.pyc
4368
0644
edit
dl
rm
ImportHooks.pyo
4368
0644
edit
dl
rm
ImportManager.py
17547
0644
edit
dl
rm
ImportManager.pyc
17284
0644
edit
dl
rm
ImportManager.pyo
17284
0644
edit
dl
rm
NameMapper.py
13093
0644
edit
dl
rm
NameMapper.pyc
14161
0644
edit
dl
rm
NameMapper.pyo
14161
0644
edit
dl
rm
Parser.py
103599
0644
edit
dl
rm
Parser.pyc
81466
0644
edit
dl
rm
Parser.pyo
81277
0644
edit
dl
rm
Servlet.py
3406
0644
edit
dl
rm
Servlet.pyc
3884
0644
edit
dl
rm
Servlet.pyo
3884
0644
edit
dl
rm
SettingsManager.py
10361
0644
edit
dl
rm
SettingsManager.pyc
11811
0644
edit
dl
rm
SettingsManager.pyo
11811
0644
edit
dl
rm
SourceReader.py
9059
0644
edit
dl
rm
SourceReader.pyc
11964
0644
edit
dl
rm
SourceReader.pyo
11964
0644
edit
dl
rm
Template.py
84747
0644
edit
dl
rm
Template.pyc
68404
0644
edit
dl
rm
Template.pyo
68320
0644
edit
dl
rm
TemplateCmdLineIface.py
3311
0644
edit
dl
rm
TemplateCmdLineIface.pyc
3986
0644
edit
dl
rm
TemplateCmdLineIface.pyo
3986
0644
edit
dl
rm
Unspecified.py
258
0644
edit
dl
rm
Unspecified.pyc
809
0644
edit
dl
rm
Unspecified.pyo
809
0644
edit
dl
rm
Version.py
1540
0644
edit
dl
rm
Version.pyc
1867
0644
edit
dl
rm
Version.pyo
1299
0644
edit
dl
rm
_namemapper.so
13576
0644
edit
dl
rm
__init__.py
582
0644
edit
dl
rm
__init__.pyc
756
0644
edit
dl
rm
__init__.pyo
756
0644
edit
dl
rm
Edit:
/usr/lib64/python2.6/site-packages/Cheetah/FileUtils.py
(10664B)
from glob import glob import os from os import listdir import os.path import re from tempfile import mktemp def _escapeRegexChars(txt, escapeRE=re.compile(r'([\$\^\*\+\.\?\{\}\[\]\(\)\|\\])')): return escapeRE.sub(r'\\\1', txt) def findFiles(*args, **kw): """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.""" return FileFinder(*args, **kw).files() def replaceStrInFiles(files, theStr, repl): """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.""" pattern = _escapeRegexChars(theStr) return FindAndReplace(files, pattern, repl).results() def replaceRegexInFiles(files, pattern, repl): """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.""" return FindAndReplace(files, pattern, repl).results() ################################################## ## CLASSES class FileFinder: """Traverses a directory tree and finds all files in it that match one of the specified glob patterns.""" def __init__(self, rootPath, globPatterns=('*',), ignoreBasenames=('CVS', '.svn'), ignoreDirs=(), ): self._rootPath = rootPath self._globPatterns = globPatterns self._ignoreBasenames = ignoreBasenames self._ignoreDirs = ignoreDirs self._files = [] self.walkDirTree(rootPath) def walkDirTree(self, dir='.', listdir=os.listdir, isdir=os.path.isdir, join=os.path.join, ): """Recursively walk through a directory tree and find matching files.""" processDir = self.processDir filterDir = self.filterDir pendingDirs = [dir] addDir = pendingDirs.append getDir = pendingDirs.pop while pendingDirs: dir = getDir() ## process this dir processDir(dir) ## and add sub-dirs for baseName in listdir(dir): fullPath = join(dir, baseName) if isdir(fullPath): if filterDir(baseName, fullPath): addDir( fullPath ) def filterDir(self, baseName, fullPath): """A hook for filtering out certain dirs. """ return not (baseName in self._ignoreBasenames or fullPath in self._ignoreDirs) def processDir(self, dir, glob=glob): extend = self._files.extend for pattern in self._globPatterns: extend( glob(os.path.join(dir, pattern)) ) def files(self): return self._files class _GenSubberFunc: """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.""" backrefRE = re.compile(r'\\([1-9][0-9]*)') groupRE = re.compile(r'\\g<([a-zA-Z_][a-zA-Z_]*)>') def __init__(self, replaceStr): self._src = replaceStr self._pos = 0 self._codeChunks = [] self.parse() def src(self): return self._src def pos(self): return self._pos def setPos(self, pos): self._pos = pos def atEnd(self): return self._pos >= len(self._src) def advance(self, offset=1): self._pos += offset def readTo(self, to, start=None): if start == None: start = self._pos self._pos = to if self.atEnd(): return self._src[start:] else: return self._src[start:to] ## match and get methods def matchBackref(self): return self.backrefRE.match(self.src(), self.pos()) def getBackref(self): m = self.matchBackref() self.setPos(m.end()) return m.group(1) def matchGroup(self): return self.groupRE.match(self.src(), self.pos()) def getGroup(self): m = self.matchGroup() self.setPos(m.end()) return m.group(1) ## main parse loop and the eat methods def parse(self): while not self.atEnd(): if self.matchBackref(): self.eatBackref() elif self.matchGroup(): self.eatGroup() else: self.eatStrConst() def eatStrConst(self): startPos = self.pos() while not self.atEnd(): if self.matchBackref() or self.matchGroup(): break else: self.advance() strConst = self.readTo(self.pos(), start=startPos) self.addChunk(repr(strConst)) def eatBackref(self): self.addChunk( 'm.group(' + self.getBackref() + ')' ) def eatGroup(self): self.addChunk( 'm.group("' + self.getGroup() + '")' ) def addChunk(self, chunk): self._codeChunks.append(chunk) ## code wrapping methods def codeBody(self): return ', '.join(self._codeChunks) def code(self): return "def subber(m):\n\treturn ''.join([%s])\n" % (self.codeBody()) def subberFunc(self): exec(self.code()) return subber class FindAndReplace: """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). """ def __init__(self, files, patternOrRE, replacement, recordResults=True): if isinstance(patternOrRE, basestring): self._regex = re.compile(patternOrRE) else: self._regex = patternOrRE if isinstance(replacement, basestring): self._subber = _GenSubberFunc(replacement).subberFunc() else: self._subber = replacement self._pattern = pattern = self._regex.pattern self._files = files self._results = {} self._recordResults = recordResults ## see if we should use pgrep to do the file matching self._usePgrep = False if (os.popen3('pgrep')[2].read()).startswith('Usage:'): ## now check to make sure pgrep understands the pattern tmpFile = mktemp() open(tmpFile, 'w').write('#') if not (os.popen3('pgrep "' + pattern + '" ' + tmpFile)[2].read()): # it didn't print an error msg so we're ok self._usePgrep = True os.remove(tmpFile) self._run() def results(self): return self._results def _run(self): regex = self._regex subber = self._subDispatcher usePgrep = self._usePgrep pattern = self._pattern for file in self._files: if not os.path.isfile(file): continue # skip dirs etc. self._currFile = file found = False if 'orig' in locals(): del orig if self._usePgrep: if os.popen('pgrep "' + pattern + '" ' + file ).read(): found = True else: orig = open(file).read() if regex.search(orig): found = True if found: if 'orig' not in locals(): orig = open(file).read() new = regex.sub(subber, orig) open(file, 'w').write(new) def _subDispatcher(self, match): if self._recordResults: if self._currFile not in self._results: res = self._results[self._currFile] = {} res['count'] = 0 res['matches'] = [] else: res = self._results[self._currFile] res['count'] += 1 res['matches'].append({'contents': match.group(), 'start': match.start(), 'end': match.end(), } ) return self._subber(match) class SourceFileStats: """ """ _fileStats = None def __init__(self, files): self._fileStats = stats = {} for file in files: stats[file] = self.getFileStats(file) def rawStats(self): return self._fileStats def summary(self): codeLines = 0 blankLines = 0 commentLines = 0 totalLines = 0 for fileStats in self.rawStats().values(): codeLines += fileStats['codeLines'] blankLines += fileStats['blankLines'] commentLines += fileStats['commentLines'] totalLines += fileStats['totalLines'] stats = {'codeLines': codeLines, 'blankLines': blankLines, 'commentLines': commentLines, 'totalLines': totalLines, } return stats def printStats(self): pass def getFileStats(self, fileName): codeLines = 0 blankLines = 0 commentLines = 0 commentLineRe = re.compile(r'\s#.*$') blankLineRe = re.compile('\s$') lines = open(fileName).read().splitlines() totalLines = len(lines) for line in lines: if commentLineRe.match(line): commentLines += 1 elif blankLineRe.match(line): blankLines += 1 else: codeLines += 1 stats = {'codeLines': codeLines, 'blankLines': blankLines, 'commentLines': commentLines, 'totalLines': totalLines, } return stats
Save
cmd:
run