dcache_copy.py
Go to the documentation of this file.
1 import os, sys
2 
3 copy_dir = "/lbne/data/users/ljf26/fluxfiles/g4lbne/v3r0p10/"
4 
5 for root, dirs, files in os.walk(copy_dir):
6  for file in files:
7 
8  from_dir = root
9  dest_dir = from_dir.replace("/lbne/data/users/","/pnfs/lbne/scratch/users/");
10 
11  print "Copying "+os.path.join(root,file)+" TO "+dest_dir
12 
13  # make directories
14  folders = dest_dir.split("/")
15  temp = "/"
16  for i in range(0,len(folders)):
17  temp = os.path.join(temp,folders[i])
18  if not os.path.exists(temp):
19  print "Making "+temp
20  os.system("ifdh mkdir "+temp)
21 
22 
23  # copy file
24  if os.path.exists(os.path.join(dest_dir,file)):
25  if (os.path.getsize(os.path.join(dest_dir,file)) ==
26  os.path.getsize(os.path.join(from_dir,file))):
27  print dest_dir+file+": File already exists and is identical..skipping"
28  if (os.path.getsize(os.path.join(dest_dir,file)) >
29  os.path.getsize(os.path.join(from_dir,file))):
30  print dest_dir+file+ ": File already exists and is bigger than source file..skipping"
31  if (os.path.getsize(os.path.join(dest_dir,file)) <
32  os.path.getsize(os.path.join(from_dir,file))):
33  print dest_dir+file+ ": File already exists but is smaller than source file... removing old file and replacing."
34  os.remove(dest_dir+file)
35 
36  if not os.path.exists(os.path.join(dest_dir,file)):
37  os.system("ifdh cp "+os.path.join(from_dir,file)+" "+os.path.join(dest_dir,file))