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.3 by paus, Mon Sep 19 21:45:41 2011 UTC vs.
Revision 1.8 by paus, Fri Jan 18 22:55:25 2013 UTC

# Line 4 | Line 4
4   #
5   # Author: C.Paus                                                                      (May 06, 2010)
6   #---------------------------------------------------------------------------------------------------
7 < import os,sys,getopt,re
7 > import os,sys,getopt,re,srm
8 > t2user = os.environ['TIER2_USER']
9  
10   def debugPrint(text):
11 <    if debug == 1:
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 23 | Line 30 | def exists(target):
30      if   re.search('/castor/cern.ch/',target):
31          debugPrint(' Identified a castor directory: ' + 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'
33 >    elif re.search('/mnt/hadoop/cms/store',target):
34 >        debugPrint(' Identified a tier-2 hadoop directory: ' + target)
35 >        target = srm.convertToUrl(target,debug)
36 >        cmd = 'srmls ' + target + ' >& /dev/null'
37      else:
38          debugPrint(' Identified a normal directory: ' + target)
39          cmd = 'ls -1 ' + target + '>& /dev/null'
40              
41      status = os.system(cmd)
42 <    debugPrint(' Status: %d' % status)
42 >    debugPrint(' Status: %d (on %s)' %(status,cmd))
43  
44      return (status == 0)
45  
# Line 39 | Line 47 | def remove(source):
47      if   re.search('/castor/cern.ch/',source):
48          debugPrint(' Identified castor file')
49          cmd = "stager_rm -M " + source + "; nsrm " + source
50 <    elif re.search('/pnfs/cmsaf.mit.edu/',source):
51 <        debugPrint(' Identified tier-2 file')
52 <        cmd = 'ssh paus@cgate.mit.edu rm -rf ' + source
50 >    elif re.search('/mnt/hadoop/cms/store/user/paus',source):
51 >        debugPrint(' Identified a tier-2 hadoop directory: ' + source)
52 >        #source = srm.convertToUrl(source,debug)
53 >        #cmd = 'srmrm ' + source + ' >& /dev/null'
54 >        cmd = 'glexec rm ' + source
55      else:
56          debugPrint(' Identified a normal directory')
57          cmd = 'rm -rf ' + source
# Line 51 | Line 61 | def remove(source):
61      status = 0
62      if exe == 1:
63          status = os.system(cmd)
64 +        if status != 0:
65 +            print ' ERROR: remove returned error %d (on %s)'%(status,cmd)
66  
67      return status
68  
69 + def removeCatalog(source,debug):
70 +    tmp = os.getpid()
71 +    pid = "%d"%tmp
72 +    # which catalog is this one in?
73 +    catalogDir = '/home/cmsprod/catalog/local'
74 +    if   re.search('/castor/cern.ch/',source):
75 +        catalogDir = '/home/cmsprod/catalog/cern'
76 +    elif re.search('/mnt/hadoop/cms/store/user/paus',source):
77 +        catalogDir = '/home/cmsprod/catalog/t2mit'
78 +    # now get the dataset and the book
79 +    f       = source.split('/')
80 +    file    = f[-1]
81 +    dataset = f[-2]
82 +    book    = f[-4] + '/' + f[-3]
83 +
84 +    dir     = catalogDir + '/' + book + '/' + dataset
85 +
86 +    # now remove the particular file from the record
87 +    cmd = 'cat ' + dir + '/RawFiles.?? | sort -u | grep -v ' + file + ' > /tmp/RawFiles.00.' + pid
88 +    execute(cmd,debug)
89 +    cmd = 'rm ' + dir + '/RawFiles.??'
90 +    execute(cmd,debug)
91 +    cmd = 'mv /tmp/RawFiles.00.' + pid + ' ' + dir + '/RawFiles.00'
92 +    execute(cmd,debug)
93 +    cmd = 'cat ' + dir + '/Files | grep -v ' + file + ' > /tmp/Files.' + pid
94 +    execute(cmd,debug)
95 +    cmd = 'mv /tmp/Files.' + pid + ' ' + dir + '/Files'
96 +    execute(cmd,debug)
97 +
98 +    return
99 +
100   #===================================================================================================
101   # Main starts here
102   #===================================================================================================
103   # Define string to explain usage of the script
104   usage =  "Usage: remove  <source>"
105   usage += "               --exe\n"
106 + usage += "               --catalog\n"
107   usage += "               --debug\n"
108   usage += "               --help\n"
109  
110   # Define the valid options which can be specified and check out the command line
111 < valid = ['exe','debug','help']
111 > valid = ['exe','catalog','debug','help']
112   try:
113      opts, args = getopt.getopt(sys.argv[1:], "", valid)
114   except getopt.GetoptError, ex:
# Line 76 | Line 120 | except getopt.GetoptError, ex:
120   # Get all parameters for the production
121   # --------------------------------------------------------------------------------------------------
122   # Set defaults for each option
123 < debug = 0
124 < exe   = 0
123 > catalog = False
124 > debug   = False
125 > exe     = 0
126  
127   # Read new values from the command line
128   for opt, arg in opts:
# Line 86 | Line 131 | for opt, arg in opts:
131          print usage
132          sys.exit(0)
133      elif opt == '--debug':
134 <        debug = 1
134 >        debug   = True
135 >    elif opt == '--catalog':
136 >        catalog = True
137      elif opt == '--exe':
138 <        exe   = 1
138 >        exe     = 1
139  
140   newArgv = []
141   for arg in sys.argv[1:]:
# Line 107 | Line 154 | if   exists(source):
154      remove(source)
155   elif not exists(source):
156      print ' ERROR: the source ('+source+') does not exist.'
157 +
158 + # Remove also the catalog entry
159 + if catalog:
160 +    removeCatalog(source,debug)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines