6 from PROCTools.getFileLists
import findTCTFiles
9 from future
import standard_library
10 standard_library.install_aliases()
15 "Get size of a file through os.stat (regular file) or rfstat (file on castor)"
21 if pfn.startswith(
"/castor/"):
23 (stat,out)=subprocess.getstatusoutput(cmd)
25 print (
"ERROR: ",cmd,
"failed.")
27 for l
in out.split(os.linesep):
28 if l.startswith(
"Size"):
30 size=
int(l[1+colon:].strip())
32 print (
"ERROR: Failed to interpret output of rfstat")
39 print (
"Can't acess regular file: ",pfn)
45 return s.f_bsize * s.f_bavail
50 if __name__==
"__main__":
52 print (
"Copy a full TCT to a (local) disk")
53 print (sys.argv[0],
"tctpath destpath")
60 sDir=os.path.normpath(sys.argv[1])
61 dDir=os.path.normpath(sys.argv[2])
63 patterns=(
".*myESD.*pool.root$",
".*myAOD.*pool.root$",
"myTAGCOMM.*root$",
"TAG.root",)
64 os.environ[
'STAGE_SVCCLASS']=
"atlascerngroupdisk"
65 os.environ[
'STAGE_HOST']=
"castoratlast3"
67 if not os.access(sDir,os.R_OK):
68 print (
"Can't read from",sDir)
71 if not os.access(dDir,os.W_OK):
74 except OSError
as why:
75 print (
"Can't write to",dDir)
80 ff=findTCTFiles(sDir,
"")
85 print (
"Searching for files to copy...")
86 for name,tci
in six.iteritems (ff._commonDirs):
87 filesToCopy=[tci[0].logfile,]
89 filesToCopy+=ff.findFilesInDir(tci[0].directory,p)
91 allFilesToCopy[name]=filesToCopy
95 for n,fs
in six.iteritems (allFilesToCopy):
102 print (
"Found %i files with a total Size of %.2f MB" % (nFiles, totalSize/(1024.0*1024.0)))
103 print (
"Start Copying:")
106 for n,fs
in six.iteritems (allFilesToCopy):
108 print (
"Working on ",n)
110 if not logpath.startswith(sDir):
111 print (
"ERROR, log file path",logpath,
"does not start with",sDir)
118 except OSError
as why:
119 print (
"Failed to create directory",destdir)
124 shutil.copy2(logpath,destdir+
"/"+os.path.basename(logpath))
125 except Exception
as why:
126 print (
"Can't copy log-file to",os.path.basename(logpath))
131 destfile=destdir+
"/"+os.path.basename(f)
132 if f. startswith(
"/castor/"):
134 cmd=
"rfcp "+f+
" "+destfile
136 (stat,out)=subprocess.getstatusoutput(cmd)
139 print (
"ERROR: ",cmd,
"failed.")
144 shutil.copy2(f,destfile)
145 except Exception
as why:
146 print (
"Can't copy file to",os.path.basename(logpath))