Created
September 9, 2011 18:18
-
-
Save capttwinky/1206937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConfigInfo(object): | |
rootDir = "/home/jpmcgrady/workspace" | |
subDir = "src" | |
class GrepDict(object): | |
def __init__(self, projName, findMe): | |
self.config = ConfigInfo | |
self.projName = projName | |
self.findMe = findMe | |
self.grepOut = False | |
self.grepIO() | |
self.grepParser() | |
def grepIO(self): | |
from subprocess import Popen, PIPE | |
self.myDir = "%s/%s/%s/"%(self.config.rootDir, self.projName, self.config.subDir) | |
print("Looking for '%s' under '%s'"%(self.findMe, self.myDir)) | |
pgrep = Popen(["grep","-nr",self.findMe,self.myDir], stdout=PIPE) | |
self.grepOut = pgrep.communicate()[0] | |
pgrep.stdout.close() | |
return True | |
def grepParser(self): | |
if not self.grepOut: | |
print("no grep results") | |
return False | |
myLines = (line.strip() for line in self.grepOut.split('\n') if line) | |
self.dictOut = {} | |
for myLine in myLines: | |
myParts = myLine.partition(':') | |
if myParts[0] and myParts[2]: | |
self.dictOut.setdefault(myParts[0],[]).append(int(myParts[2].partition(':')[0])) | |
if not self.dictOut: | |
print "no results found, exiting" | |
return True | |
screenMax() | |
print("Results for '%s' under '%s'"%(self.findMe, self.myDir)) | |
for myK in sorted(self.dictOut.keys()): | |
print "%s: %s"%(myK.replace(self.config.rootDir,''), ", ".join((str(me) for me in sorted(self.dictOut[myK])))) | |
return True | |
def screenMax(): | |
myThis = True | |
while myThis: | |
myThis = raw_input("calculations complete, please maximize screen, then press enter!") | |
if __name__=='__main__': | |
myGrep = GrepDict('asiango','LOGOUTPUT') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment