import shutil, re, glob, sys, os from stat import * ERROR_STR= """Error removing %(path)s, %(error)s """ def rmgeneric(path, __func__): try: # print 'Removing file ', path __func__(path) # print 'Removed ', path except OSError, (errno, strerror): print ERROR_STR % {'path' : path, 'error': strerror }, errno def removeall(path): if not os.path.isdir(path): return files=os.listdir(path) for x in files: # print 'Removing ', x fullpath=os.path.join(path, x) if os.path.isfile(fullpath): os.chmod(fullpath, S_IWRITE) f=os.remove rmgeneric(fullpath, f) elif os.path.isdir(fullpath): removeall(fullpath) f=os.rmdir rmgeneric(fullpath, f) def del_temp_dir(dir): if dir: print 'Removing dir', dir if os.path.isdir(dir): removeall(dir) os.rmdir(dir) def temp_dir(log_file): pat = re.compile(".*Perforce repository directory (.*)\.$") #print "processing " + log_file result = [] input = open(log_file) for line in input: # print "line: " + line match = pat.match(line) if match: dir = match.group(1) print "Temp dir: " + dir result.append(dir) input.close() return result def main(): dirs = [] for file in ARGV: dirs.extend(temp_dir(file)) for dir in dirs: del_temp_dir(dir) if __name__ == '__main__': import sys, glob ARGV = sys.argv[1:] or glob.glob("*.log") main()