4 |
|
# |
5 |
|
# Author: C.Paus (May 06, 2010) |
6 |
|
#--------------------------------------------------------------------------------------------------- |
7 |
< |
import os,sys,getopt,re |
7 |
> |
import os,sys,getopt,re,srm |
8 |
|
|
9 |
|
def debugPrint(text): |
10 |
< |
if debug == 1: |
10 |
> |
if debug: |
11 |
|
print ' DEBUG: ' + text |
12 |
|
|
13 |
|
def clean(file): |
25 |
|
cmd = 'rfdir ' + target |
26 |
|
elif re.search('/pnfs/cmsaf.mit.edu/',target): |
27 |
|
debugPrint(' Identified a tier-2 directory: ' + target) |
28 |
< |
cmd = 'ssh paus@cgate.mit.edu ls -1 ' + target + '\>\& /dev/null' |
28 |
> |
cmd = 'ssh paus@cgate.mit.edu ls -1 ' + target + ' \>\& /dev/null' |
29 |
> |
elif re.search('/mnt/hadoop/cms/store',target): |
30 |
> |
debugPrint(' Identified a tier-2 hadoop directory: ' + target) |
31 |
> |
target = srm.convertToUrl(target,debug) |
32 |
> |
cmd = 'srmls ' + target + ' >& /dev/null' |
33 |
|
else: |
34 |
|
debugPrint(' Identified a normal directory: ' + target) |
35 |
|
cmd = 'ls -1 ' + target + '>& /dev/null' |
36 |
|
|
37 |
|
status = os.system(cmd) |
38 |
< |
debugPrint(' Status: %d' % status) |
38 |
> |
debugPrint(' Status: %d (on %s)' %(status,cmd)) |
39 |
|
|
40 |
|
return (status == 0) |
41 |
|
|
46 |
|
elif re.search('/pnfs/cmsaf.mit.edu/',source): |
47 |
|
debugPrint(' Identified tier-2 file') |
48 |
|
cmd = 'ssh paus@cgate.mit.edu rm -rf ' + source |
49 |
+ |
elif re.search('/mnt/hadoop/cms/store/user/paus',source): |
50 |
+ |
debugPrint(' Identified a tier-2 hadoop directory: ' + source) |
51 |
+ |
source = srm.convertToUrl(source,debug) |
52 |
+ |
cmd = 'srmrm ' + source + ' >& /dev/null' |
53 |
|
else: |
54 |
|
debugPrint(' Identified a normal directory') |
55 |
|
cmd = 'rm -rf ' + source |
59 |
|
status = 0 |
60 |
|
if exe == 1: |
61 |
|
status = os.system(cmd) |
62 |
+ |
if status != 0: |
63 |
+ |
print ' ERROR: remove returned error %d (on %s)'%(status,cmd) |
64 |
|
|
65 |
|
return status |
66 |
|
|
86 |
|
# Get all parameters for the production |
87 |
|
# -------------------------------------------------------------------------------------------------- |
88 |
|
# Set defaults for each option |
89 |
< |
debug = 0 |
89 |
> |
debug = False |
90 |
|
exe = 0 |
91 |
|
|
92 |
|
# Read new values from the command line |
96 |
|
print usage |
97 |
|
sys.exit(0) |
98 |
|
elif opt == '--debug': |
99 |
< |
debug = 1 |
99 |
> |
debug = True |
100 |
|
elif opt == '--exe': |
101 |
|
exe = 1 |
102 |
|
|