/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/bin/env python import os, time, re, optparse usage = ''' ''' parser = optparse.OptionParser(usage=usage, version='%prog v0.2') parser.add_option('--path', dest='path', help='provided path to log dir.') #parser.add_option('--', dest='', help='') (options, args) = parser.parse_args() # # This function takes a top level path as argument then generates a file list with up to 1 deep nested directories. # Filenames containing only numbers are not added to this list # questions: # Will sorting lists prior to for loop make it run faster? initial time to scan buildbot logdirs: 23 minutes # def genFileList(path): startTime = time.time() filelistA = os.listdir(path) filelistB = list() filelistC = list() for file in filelistA: if not file.isdigit() and not os.path.isdir(os.path.join(path, file)): filelistB.append(os.path.join(path, file)) if not file.isdigit() and os.path.isdir(os.path.join(path, file)): filelistC = os.listdir(os.path.join(path, file)) for nestedfile in filelistC: if not nestedfile.isdigit() and not os.path.isdir(os.path.join(path, file, nestedfile)): filelistB.append(os.path.join(path, file, nestedfile)) finishTime = time.time() - startTime print 'total run time: %s' % finishTime return filelistB # ------------- End function # # get the last modification time in epoch and filesize # def getFileMtimeStat(filepath): if os.path.isfile(filepath): filemtime = time.localtime(os.stat(filepath).st_mtime) filesize = os.stat(filepath).st_size return filepath, filemtime, filesize # ------------- End function if options.path: files = genFileList(options.path) fileInfo = [getFileMtimeStat(file) for file in files] fileInfo.sort() for line in fileInfo: print line print len(fileInfo)