#!/usr/bin/env python # -*- coding: UTF-8 -*- from os.path import * import os,sys fileExtensions=set() #fileExtensions.add("ppt") #fileExtensions.add("doc") #fileExtensions.add("xsl") #fileExtensions.add("pdf") def findFiles(allowedTypes=fileExtensions): for root, dirs, files in os.walk("./"): for f in files: for ext in fileExtensions: if (f.endswith(ext)): yield (root+"/"+f) break # Ok we proceed class InternalCommand: def process(self,fname): print "Processing:",fname def getResult(self): return None class printfilename(InternalCommand): def process(self,fname): print fname class wc(InternalCommand): def __init__(self): self.lineCount=0 def process(self,fname): self.lineCount=self.lineCount+len(file(fname,"r").readlines()) def getResult(self): return str(self.lineCount)+" lines" ####Main GLOBAL_COMMANDS=[] if len(sys.argv)>1: for f in sys.argv[1:]: if f.startswith("-"): command=f[1:] print "Adding Command:",command #print eval(command+"()") GLOBAL_COMMANDS.append( eval(command+"()")) else: fileExtensions.add(f) print "File Extensions:", " / ".join(fileExtensions) counter=0 for fname in findFiles(fileExtensions): #print fname for commandClass in GLOBAL_COMMANDS: commandClass.process(fname) counter=counter+1 #if(counter % 101) == 0: # print "\r Processing", counter print "===============================================" print "Total Files:",counter for commandClass in GLOBAL_COMMANDS: r=commandClass.getResult() if r: print str(commandClass.__class__), str(r) print "==============================================="