ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/joshmt/onlyLast.py
(Generate patch)

Comparing UserCode/joshmt/onlyLast.py (file contents):
Revision 1.2 by joshmt, Wed Aug 25 10:15:46 2010 UTC vs.
Revision 1.4 by wteo, Fri Sep 2 14:03:35 2011 UTC

# Line 9 | Line 9 | import os, sys, re
9   #file names like this:
10   #                      myfilename_1_1_aBC.root
11  
12 + # 02/09/11 - Don
13 + # updated to handle files on the T3
14 + # this script now automatically checks if the input dir is pointing
15 + # to the T3 and adapts accordingly
16 + # e.g. python onlyLast.py "$CUSE/blah"
17 +
18   ###############################################################
19  
20   #handle input arguments
# Line 17 | Line 23 | import os, sys, re
23   ##    print arg
24      
25   #sys.argv[1] will have the first argument
26 < tmpfile = '/tmp/joshmt/onlyLast_py_'
26 > tmpfile = '.onlyLast_py_'
27   mypid = os.getpid()
28   tmpfile += `mypid`
29  
30 +
31   inputdir = sys.argv[1]
32   if inputdir[len(inputdir)-1] != '/':
33      inputdir+='/'
34  
35 + #check if the input directory is located on the T3
36 + isT3 = False
37 + checkT3 = 'echo '
38 + checkT3 += inputdir
39 + checkT3 += ' | awk -F "/" \'{print $1}\' '
40 + p = os.popen(checkT3)
41 + location = p.readline()
42 + p.close()
43 + #print location
44 + if "srm" in location:
45 +        print "T3 directory specified.  Using grid commands."
46 +        isT3 = True
47 +
48 +
49   outputdir = inputdir
50   outputdir += 'EXTRAS'
51  
52   mkdircommand = "nsmkdir "
53   mkdircommand += outputdir
54  
55 + #if isT3 == 'T3':
56 + #    mkdircommand = "srmmkdir "
57 + #    mkdircommand += outputdir
58 +
59 +
60   #get a file listing into tmpfile
61   cmd = 'nsls -l '
62   cmd += inputdir
63   cmd += ' | awk \'// {print $5,$9;}\' > '
64 < cmd += tmpfile
64 >
65 >
66 > if isT3 == True:
67 >    cmd = 'srmls "'
68 >    cmd += inputdir
69 >    cmd += '" | awk -F "/" \'{print $1,$NF}\' | awk \'NF>0\'  > '
70 >
71 >
72 > cmd+= tmpfile
73   #print cmd
74   os.system(cmd)
75  
76   #keep track of whether we made the directory or not
77   alreadymadedir = 0
78 + #do not manually make the directory for the T3, lcg-cp will take care of it
79 + if isT3 == True:
80 +    alreadymadedir = 1
81 +
82 +
83 +
84  
85   f = open(tmpfile,'r')
86  
# Line 104 | Line 144 | for ii in indexdict:
144              s+=jj
145              print "moving ", s
146              cpcmd = 'rfcp '
147 +            if isT3 == True:
148 +                cpcmd = 'lcg-cp --verbose -b -D srmv2 "'
149              cpcmd += s
150 <            cpcmd += ' '
150 >
151 >            if isT3 == True:
152 >                cpcmd += '" "'
153 >            else: cpcmd += ' '
154 >
155              cpcmd += outputdir
156 +            if isT3 == True:
157 +                cpcmd +='/'
158 +                cpcmd +=jj
159 +                cpcmd += '"'
160              print cpcmd
161              os.system(cpcmd)
162              rmcmd = 'rfrm '
163 +            if isT3 == True:
164 +                rmcmd = 'srmrm '
165              rmcmd += s
166              print rmcmd
167              os.system(rmcmd)
# Line 121 | Line 173 | os.remove(tmpfile)
173   print "----------------------------"
174   print "I moved this many files: ",nmoved
175   print "----------------------------"
176 +
177 +
178 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines