ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/remove
Revision: 1.2
Committed: Tue Sep 21 20:09:09 2010 UTC (14 years, 7 months ago) by paus
Branch: MAIN
CVS Tags: Mit_024b, Mit_025pre1, Mit_024a, Mit_024, Mit_023, Mit_022a, Mit_022, Mit_020d, TMit_020d, Mit_020c, Mit_021, Mit_021pre2, Mit_021pre1, Mit_020b, Mit_020a, Mit_020, Mit_020pre1, Mit_018, Mit_017, Mit_017pre3, Mit_017pre2, Mit_017pre1, Mit_016, Mit_015b, Mit_015a, Mit_015, Mit_014c, Mit_014e, Mit_014d
Changes since 1.1: +12 -7 lines
Log Message:
Update before going to 014e tag and version 3_8_4.

File Contents

# Content
1 #!/usr/bin/env python
2 #---------------------------------------------------------------------------------------------------
3 # Script to move a file from one place to another. Restrictions to application of course apply :-)
4 #
5 # Author: C.Paus (May 06, 2010)
6 #---------------------------------------------------------------------------------------------------
7 import os,sys,getopt,re
8
9 def debugPrint(text):
10 if debug == 1:
11 print ' DEBUG: ' + text
12
13 def clean(file):
14 if re.search('dcap:',file):
15 g = file.split('/')
16 file = '/'.join(g[3:])
17 debugPrint(' Cleaned: ' + file)
18
19 return file
20
21
22 def exists(target):
23 if re.search('/castor/cern.ch/',target):
24 debugPrint(' Identified a castor directory: ' + target)
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'
29 else:
30 debugPrint(' Identified a normal directory: ' + target)
31 cmd = 'ls -1 ' + target + '>& /dev/null'
32
33 status = os.system(cmd)
34 debugPrint(' Status: %d' % status)
35
36 return (status == 0)
37
38 def remove(source):
39 if re.search('/castor/cern.ch/',source):
40 debugPrint(' Identified castor file')
41 cmd = "stager_rm -M " + source + "; nsrm " + source
42 elif re.search('/pnfs/cmsaf.mit.edu/',source):
43 debugPrint(' Identified tier-2 file')
44 cmd = 'ssh paus@cgate.mit.edu rm -rf ' + source
45 else:
46 debugPrint(' Identified a normal directory')
47 cmd = 'rm -rf ' + source
48
49 # ready to perform the requested operation
50 debugPrint(' -> removing with: ' + cmd)
51 status = 0
52 if exe == 1:
53 status = os.system(cmd)
54
55 return status
56
57 #===================================================================================================
58 # Main starts here
59 #===================================================================================================
60 # Define string to explain usage of the script
61 usage = "Usage: remove <source>"
62 usage += " --exe\n"
63 usage += " --debug\n"
64 usage += " --help\n"
65
66 # Define the valid options which can be specified and check out the command line
67 valid = ['exe','debug','help']
68 try:
69 opts, args = getopt.getopt(sys.argv[1:], "", valid)
70 except getopt.GetoptError, ex:
71 print usage
72 print str(ex)
73 sys.exit(1)
74
75 # --------------------------------------------------------------------------------------------------
76 # Get all parameters for the production
77 # --------------------------------------------------------------------------------------------------
78 # Set defaults for each option
79 debug = 0
80 exe = 0
81
82 # Read new values from the command line
83 for opt, arg in opts:
84 #print ' OPT , ARG: ' + opt + ' ' + arg
85 if opt == '--help':
86 print usage
87 sys.exit(0)
88 elif opt == '--debug':
89 debug = 1
90 elif opt == '--exe':
91 exe = 1
92
93 newArgv = []
94 for arg in sys.argv[1:]:
95 #print ' ARG: ' + arg
96 if arg[:2] == "--":
97 continue
98 else:
99 newArgv.append(arg)
100
101 # Define source and target
102 source = clean(newArgv[0])
103
104 # Test whether the source exists
105 if exists(source):
106 debugPrint("\n Removing: " + source)
107 remove(source)
108 elif not exists(source):
109 print ' ERROR: the source ('+source+') does not exist.'