-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakeFileList.py
More file actions
executable file
·96 lines (73 loc) · 2.19 KB
/
makeFileList.py
File metadata and controls
executable file
·96 lines (73 loc) · 2.19 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
87
88
89
90
91
92
93
94
95
#!/usr/bin/python
#
import sys,string,math,os,subprocess,socket
import socket
EOS = None
hostname = socket.gethostname()
if "lxplus" in hostname:
EOS = "/afs/cern.ch/project/eos/installation/0.3.84-aquamarine/bin/eos.select"
if "fnal.gov" in hostname:
EOS = "eos root://cmseos.fnal.gov"
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):
cmd = " ".join( [command, subcommand, inDir])
p1 = subprocess.Popen(cmd, shell=True, 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):
isRootFile=False
(stdout, stderr)=runPopen(eos,command,inDir)
output=stdout.split(' ')
if output == ['']:
return inDir.find(".root") >-1
# if Debug: print len(output),output
if output[3].find(".root")>-1:
if Debug: print len(output),output
isRootFile=True
return isRootFile
if __name__ == '__main__':
narg=len(sys.argv)
if narg != 2:
print "Please specify EOS directory"
sys.exit(1)
inDir=sys.argv[1]
## print inDir
rootfiles=listFiles(inDir)
for rootfile in rootfiles:
if "lxplus" in hostname:
theFile="root://eoscms.cern.ch/" + rootfile
if "fnal.gov" in hostname:
theFile="root://cmseos.fnal.gov/" + rootfile
print theFile