ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/remove
(Generate patch)

Comparing UserCode/MitProd/Processing/bin/remove (file contents):
Revision 1.4 by paus, Thu Oct 20 23:16:23 2011 UTC vs.
Revision 1.6 by paus, Wed Jul 25 03:05:45 2012 UTC

# Line 5 | Line 5
5   # Author: C.Paus                                                                      (May 06, 2010)
6   #---------------------------------------------------------------------------------------------------
7   import os,sys,getopt,re,srm
8 + t2user = os.environ['TIER2_USER']
9  
10   def debugPrint(text):
11      if debug:
12          print ' DEBUG: ' + text
13  
14 + def execute(cmd,debug):
15 +    if debug:
16 +        print ' DEBUG: ' + cmd
17 +    else:
18 +        os.system(cmd)
19 +
20   def clean(file):
21      if   re.search('dcap:',file):
22          g = file.split('/')
# Line 25 | Line 32 | def exists(target):
32          cmd = 'rfdir ' + target
33      elif re.search('/pnfs/cmsaf.mit.edu/',target):
34          debugPrint(' Identified a tier-2 directory: ' + target)
35 <        cmd = 'ssh paus@cgate.mit.edu ls -1 ' + target + ' \>\& /dev/null'
35 >        cmd = 'ssh ' + t2user + '@cgate.mit.edu ls -1 ' + target + ' \>\& /dev/null'
36      elif re.search('/mnt/hadoop/cms/store',target):
37          debugPrint(' Identified a tier-2 hadoop directory: ' + target)
38          target = srm.convertToUrl(target,debug)
# Line 45 | Line 52 | def remove(source):
52          cmd = "stager_rm -M " + source + "; nsrm " + source
53      elif re.search('/pnfs/cmsaf.mit.edu/',source):
54          debugPrint(' Identified tier-2 file')
55 <        cmd = 'ssh paus@cgate.mit.edu rm -rf ' + source
55 >        cmd = 'ssh ' + t2user + '@cgate.mit.edu rm -rf ' + source
56      elif re.search('/mnt/hadoop/cms/store/user/paus',source):
57          debugPrint(' Identified a tier-2 hadoop directory: ' + source)
58          source = srm.convertToUrl(source,debug)
# Line 64 | Line 71 | def remove(source):
71  
72      return status
73  
74 + def removeCatalog(source,debug):
75 +    tmp = os.getpid()
76 +    pid = "%d"%tmp
77 +    # which catalog is this one in?
78 +    catalogDir = '/home/cmsprod/catalog/local'
79 +    if   re.search('/castor/cern.ch/',source):
80 +        catalogDir = '/home/cmsprod/catalog/cern'
81 +    elif re.search('/pnfs/cmsaf.mit.edu/',source) or \
82 +         re.search('/mnt/hadoop/cms/store/user/paus',source):
83 +        catalogDir = '/home/cmsprod/catalog/t2mit'
84 +    # now get the dataset and the book
85 +    f       = source.split('/')
86 +    file    = f[-1]
87 +    dataset = f[-2]
88 +    book    = f[-4] + '/' + f[-3]
89 +
90 +    dir     = catalogDir + '/' + book + '/' + dataset
91 +
92 +    # now remove the particular file from the record
93 +    cmd = 'cat ' + dir + '/RawFiles.?? | sort -u | grep -v ' + file + ' > /tmp/RawFiles.00.' + pid
94 +    execute(cmd,debug)
95 +    cmd = 'rm ' + dir + '/RawFiles.??'
96 +    execute(cmd,debug)
97 +    cmd = 'mv /tmp/RawFiles.00.' + pid + ' ' + dir + '/RawFiles.00'
98 +    execute(cmd,debug)
99 +    cmd = 'cat ' + dir + '/Files | grep -v ' + file + ' > /tmp/Files.' + pid
100 +    execute(cmd,debug)
101 +    cmd = 'mv /tmp/Files.' + pid + ' ' + dir + '/Files'
102 +    execute(cmd,debug)
103 +
104 +    return
105 +
106   #===================================================================================================
107   # Main starts here
108   #===================================================================================================
109   # Define string to explain usage of the script
110   usage =  "Usage: remove  <source>"
111   usage += "               --exe\n"
112 + usage += "               --catalog\n"
113   usage += "               --debug\n"
114   usage += "               --help\n"
115  
116   # Define the valid options which can be specified and check out the command line
117 < valid = ['exe','debug','help']
117 > valid = ['exe','catalog','debug','help']
118   try:
119      opts, args = getopt.getopt(sys.argv[1:], "", valid)
120   except getopt.GetoptError, ex:
# Line 86 | Line 126 | except getopt.GetoptError, ex:
126   # Get all parameters for the production
127   # --------------------------------------------------------------------------------------------------
128   # Set defaults for each option
129 < debug = False
130 < exe   = 0
129 > catalog = False
130 > debug   = False
131 > exe     = 0
132  
133   # Read new values from the command line
134   for opt, arg in opts:
# Line 96 | Line 137 | for opt, arg in opts:
137          print usage
138          sys.exit(0)
139      elif opt == '--debug':
140 <        debug = True
140 >        debug   = True
141 >    elif opt == '--catalog':
142 >        catalog = True
143      elif opt == '--exe':
144 <        exe   = 1
144 >        exe     = 1
145  
146   newArgv = []
147   for arg in sys.argv[1:]:
# Line 117 | Line 160 | if   exists(source):
160      remove(source)
161   elif not exists(source):
162      print ' ERROR: the source ('+source+') does not exist.'
163 +
164 + # Remove also the catalog entry
165 + if catalog:
166 +    removeCatalog(source,debug)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines