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.5 by paus, Tue Feb 28 11:54:36 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines