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