6 from PROCTools.getFileLists
import findTCTFiles
8 from future
import standard_library
9 standard_library.install_aliases()
14 "Get size of a file through os.stat (regular file) or rfstat (file on castor)"
20 if pfn.startswith(
"/castor/"):
22 (stat,out)=subprocess.getstatusoutput(cmd)
24 print (
"ERROR: ",cmd,
"failed.")
26 for l
in out.split(os.linesep):
27 if l.startswith(
"Size"):
29 size=
int(l[1+colon:].strip())
31 print (
"ERROR: Failed to interpret output of rfstat")
38 print (
"Can't acess regular file: ",pfn)
44 return s.f_bsize * s.f_bavail
49 if __name__==
"__main__":
51 print (
"Copy a full TCT to a (local) disk")
52 print (sys.argv[0],
"tctpath destpath")
59 sDir=os.path.normpath(sys.argv[1])
60 dDir=os.path.normpath(sys.argv[2])
62 patterns=(
".*myESD.*pool.root$",
".*myAOD.*pool.root$",
"myTAGCOMM.*root$",
"TAG.root",)
63 os.environ[
'STAGE_SVCCLASS']=
"atlascerngroupdisk"
64 os.environ[
'STAGE_HOST']=
"castoratlast3"
66 if not os.access(sDir,os.R_OK):
67 print (
"Can't read from",sDir)
70 if not os.access(dDir,os.W_OK):
73 except OSError
as why:
74 print (
"Can't write to",dDir)
79 ff=findTCTFiles(sDir,
"")
84 print (
"Searching for files to copy...")
85 for name,tci
in ff._commonDirs.items():
86 filesToCopy=[tci[0].logfile,]
88 filesToCopy+=ff.findFilesInDir(tci[0].directory,p)
90 allFilesToCopy[name]=filesToCopy
94 for n,fs
in allFilesToCopy.items():
101 print (
"Found %i files with a total Size of %.2f MB" % (nFiles, totalSize/(1024.0*1024.0)))
102 print (
"Start Copying:")
105 for n,fs
in allFilesToCopy.items():
107 print (
"Working on ",n)
109 if not logpath.startswith(sDir):
110 print (
"ERROR, log file path",logpath,
"does not start with",sDir)
117 except OSError
as why:
118 print (
"Failed to create directory",destdir)
123 shutil.copy2(logpath,destdir+
"/"+os.path.basename(logpath))
124 except Exception
as why:
125 print (
"Can't copy log-file to",os.path.basename(logpath))
130 destfile=destdir+
"/"+os.path.basename(f)
131 if f. startswith(
"/castor/"):
133 cmd=
"rfcp "+f+
" "+destfile
135 (stat,out)=subprocess.getstatusoutput(cmd)
138 print (
"ERROR: ",cmd,
"failed.")
143 shutil.copy2(f,destfile)
144 except Exception
as why:
145 print (
"Can't copy file to",os.path.basename(logpath))