|
| 1 | +#!/usr/bin/python |
| 2 | +# |
| 3 | + |
| 4 | +import sys,string,math,os,subprocess,socket |
| 5 | + |
| 6 | +EOS = "/afs/cern.ch/project/eos/installation/0.3.84-aquamarine/bin/eos.select" |
| 7 | + |
| 8 | +Debug=False |
| 9 | +# Debug=True |
| 10 | + |
| 11 | +def listFiles(inDir): |
| 12 | + |
| 13 | + dirs=[] |
| 14 | + files=getFiles(EOS,"ls",inDir) |
| 15 | + for ifile in files: |
| 16 | + theFile=os.path.join(inDir,ifile) |
| 17 | + isDir=getFileType(EOS,"stat",theFile) |
| 18 | + if isDir: |
| 19 | + print "d: ",theFile |
| 20 | + dirs.append(theFile) |
| 21 | + else: |
| 22 | + pass |
| 23 | + # print "x: ",theFile |
| 24 | + return dirs |
| 25 | + |
| 26 | +def runPopen(command,subcommand,inDir): |
| 27 | + p1 = subprocess.Popen([command, subcommand, inDir], shell=False, stdout=subprocess.PIPE) |
| 28 | + (stdout, stderr)=p1.communicate() |
| 29 | + if stderr is not None: |
| 30 | + print "Trouble executing the srmls command" |
| 31 | + sys.exit(1) |
| 32 | + |
| 33 | + ## if Debug: |
| 34 | + ## print "Raw output" |
| 35 | + ## print stdout |
| 36 | + ## print "Done\n" |
| 37 | + |
| 38 | + return (stdout,stderr) |
| 39 | + |
| 40 | +def getFiles(eos,command,inDir): |
| 41 | + |
| 42 | + (stdout, stderr)=runPopen(eos,command,inDir) |
| 43 | + |
| 44 | + tmpfiles=stdout.split('\n') |
| 45 | + files=[] |
| 46 | + for tfile in tmpfiles: |
| 47 | + if len(tfile)>0: |
| 48 | + files.append(tfile) |
| 49 | + |
| 50 | + if Debug: |
| 51 | + print "\n Number of files in Directory: ",len(files),"\n" |
| 52 | + print files |
| 53 | + |
| 54 | + return files |
| 55 | + |
| 56 | +def getFileType(eos,command,inDir): |
| 57 | + |
| 58 | + isDir=False |
| 59 | + |
| 60 | + (stdout, stderr)=runPopen(eos,command,inDir) |
| 61 | + output=stdout.split(' ') |
| 62 | + # if Debug: print len(output),output |
| 63 | + |
| 64 | + if output[4].find("directory")>-1 and output[3].find("failed")==-1 and output[3].find("log")==-1: |
| 65 | + if Debug: print len(output),output |
| 66 | + isDir=True |
| 67 | + |
| 68 | + return isDir |
| 69 | + |
| 70 | +if __name__ == '__main__': |
| 71 | + |
| 72 | + narg=len(sys.argv) |
| 73 | + if narg != 2: |
| 74 | + print "Please specify EOS directory" |
| 75 | + sys.exit(1) |
| 76 | + |
| 77 | + inDir=sys.argv[1] |
| 78 | + print inDir |
| 79 | + |
| 80 | + while True: |
| 81 | + dirs=listFiles(inDir) |
| 82 | + ## print dirs |
| 83 | + if len(dirs)==0: |
| 84 | + break |
| 85 | + else: |
| 86 | + inDir=os.path.join(inDir,dirs[0]) |
| 87 | + |
0 commit comments