6 from PROCTools.getFileLists
import findTCTFiles
12 "Get size of a file through os.stat (regular file) or rfstat (file on castor)"
18 if pfn.startswith(
"/castor/"):
20 (stat,out)=subprocess.getstatusoutput(cmd)
22 print (
"ERROR: ",cmd,
"failed.")
24 for l
in out.split(os.linesep):
25 if l.startswith(
"Size"):
27 size=
int(l[1+colon:].strip())
29 print (
"ERROR: Failed to interpret output of rfstat")
36 print (
"Can't acess regular file: ",pfn)
42 return s.f_bsize * s.f_bavail
47 if __name__==
"__main__":
49 print (
"Copy a full TCT to a (local) disk")
50 print (sys.argv[0],
"tctpath destpath")
57 sDir=os.path.normpath(sys.argv[1])
58 dDir=os.path.normpath(sys.argv[2])
60 patterns=(
".*myESD.*pool.root$",
".*myAOD.*pool.root$",
"myTAGCOMM.*root$",
"TAG.root",)
61 os.environ[
'STAGE_SVCCLASS']=
"atlascerngroupdisk"
62 os.environ[
'STAGE_HOST']=
"castoratlast3"
64 if not os.access(sDir,os.R_OK):
65 print (
"Can't read from",sDir)
68 if not os.access(dDir,os.W_OK):
71 except OSError
as why:
72 print (
"Can't write to",dDir)
77 ff=findTCTFiles(sDir,
"")
82 print (
"Searching for files to copy...")
83 for name,tci
in ff._commonDirs.items():
84 filesToCopy=[tci[0].logfile,]
86 filesToCopy+=ff.findFilesInDir(tci[0].directory,p)
88 allFilesToCopy[name]=filesToCopy
92 for n,fs
in allFilesToCopy.items():
99 print (
"Found %i files with a total Size of %.2f MB" % (nFiles, totalSize/(1024.0*1024.0)))
100 print (
"Start Copying:")
103 for n,fs
in allFilesToCopy.items():
105 print (
"Working on ",n)
107 if not logpath.startswith(sDir):
108 print (
"ERROR, log file path",logpath,
"does not start with",sDir)
115 except OSError
as why:
116 print (
"Failed to create directory",destdir)
121 shutil.copy2(logpath,destdir+
"/"+os.path.basename(logpath))
122 except Exception
as why:
123 print (
"Can't copy log-file to",os.path.basename(logpath))
128 destfile=destdir+
"/"+os.path.basename(f)
129 if f. startswith(
"/castor/"):
131 cmd=
"rfcp "+f+
" "+destfile
133 (stat,out)=subprocess.getstatusoutput(cmd)
136 print (
"ERROR: ",cmd,
"failed.")
141 shutil.copy2(f,destfile)
142 except Exception
as why:
143 print (
"Can't copy file to",os.path.basename(logpath))