ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/move
Revision: 1.7
Committed: Wed Oct 19 10:43:11 2011 UTC (13 years, 6 months ago) by paus
Branch: MAIN
CVS Tags: Mit_025c_branch1, Mit_025c_branch0, Mit_025c, Mit_025b, Mit_025a
Branch point for: Mit_025c_branch
Changes since 1.6: +15 -0 lines
Log Message:
Updates realted to hadoop move of Tier-2.

File Contents

# User Rev Content
1 paus 1.2 #!/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 paus 1.7 import srm
9 paus 1.2
10     def debugPrint(text):
11     if debug ==1:
12     print ' DEBUG: ' + text
13    
14     def clean(file):
15     if re.search('dcap:',file):
16     g = file.split('/')
17     file = '/'.join(g[3:])
18 paus 1.7 if re.search('root:',file):
19     g = file.split('/')
20     file = '/'.join(g[3:])
21     file = '/mnt/hadoop/cms' + file
22 paus 1.2 debugPrint(' Cleaned: ' + file)
23    
24     return file
25    
26    
27     def exists(target):
28     if re.search('/castor/cern.ch/',target):
29     debugPrint(' Identified a castor directory: ' + target)
30 ceballos 1.6 cmd = 'rfdir ' + target + '>& /dev/null'
31 paus 1.2 elif re.search('/pnfs/cmsaf.mit.edu/',target):
32     debugPrint(' Identified a tier-2 directory: ' + target)
33 ceballos 1.6 cmd = 'ssh paus@cgate.mit.edu ls -1 ' + target + ' \>\& /dev/null'
34 paus 1.7 elif re.search('/mnt/hadoop/cms/store',target):
35     debugPrint(' Identified a tier-2 directory: ' + target)
36     cmd = 'ssh paus@se01.cmsaf.mit.edu ls -1 ' + target + ' \>\& /dev/null'
37 paus 1.2 else:
38     debugPrint(' Identified a normal directory: ' + target)
39 ceballos 1.6 cmd = 'ls -1 ' + target + '>\& /dev/null'
40 paus 1.2
41     status = os.system(cmd)
42     debugPrint(' Status: %d' % status)
43    
44     return (status == 0)
45    
46     def move(source,target):
47     if re.search('/castor/cern.ch/',source) and re.search('/castor/cern.ch/',target):
48     debugPrint(' Identified two castor directories')
49 ceballos 1.6 cmd = 'nsrename ' + source + ' ' + target
50 paus 1.2 elif re.search('/pnfs/cmsaf.mit.edu/',source) and re.search('/pnfs/cmsaf.mit.edu/',target):
51     debugPrint(' Identified two tier-2 directories')
52     cmd = 'ssh paus@cgate.mit.edu mv ' + source + ' ' + target
53 paus 1.7 elif re.search('/mnt/hadoop/cms/store',target):
54     urlSource = srm.convertToUrl(source,False)
55     urlTarget = srm.convertToUrl(target,False)
56     cmd = 'srmmv ' + urlSource + ' ' + urlTarget + ' >& /dev/null'
57     cmd = 'glexec mv ' + source + ' ' + target ## + ' >& /dev/null'
58     #debugPrint(' Identified a tier-2 directory: ' + target)
59     #cmd = 'ssh paus@se01.cmsaf.mit.edu ls -1 ' + target + ' \>\& /dev/null'
60 paus 1.2 else:
61     debugPrint(' Identified a normal directory')
62     cmd = 'mv ' + source + ' ' + target
63    
64     # ready to perfrom the requested operation
65     debugPrint(' -> moving with: ' + cmd)
66     ## status = 0
67     status = os.system(cmd)
68    
69     return status
70    
71     #===================================================================================================
72     # Main starts here
73     #===================================================================================================
74     # Define string to explain usage of the script
75     usage = "Usage: list <source> <target>"
76     usage += " --debug\n"
77     usage += " --help\n"
78    
79     # Define the valid options which can be specified and check out the command line
80     valid = ['debug','help']
81     try:
82     opts, args = getopt.getopt(sys.argv[1:], "", valid)
83     except getopt.GetoptError, ex:
84     print usage
85     print str(ex)
86     sys.exit(1)
87    
88     # --------------------------------------------------------------------------------------------------
89     # Get all parameters for the production
90     # --------------------------------------------------------------------------------------------------
91     # Set defaults for each option
92     debug = 0
93    
94     # Read new values from the command line
95     for opt, arg in opts:
96     #print ' OPT , ARG: ' + opt + ' ' + arg
97     if opt == '--help':
98     print usage
99     sys.exit(0)
100     elif opt == '--debug':
101     debug = 1
102    
103     newArgv = []
104     for arg in sys.argv[1:]:
105     #print ' ARG: ' + arg
106     if arg[:2] == "--":
107     continue
108     else:
109     newArgv.append(arg)
110    
111     # Define source and target
112     source = clean(newArgv[0])
113     target = clean(newArgv[1])
114    
115     # Test whether the source exists and that the target does not exist
116     if exists(source) and not exists(target):
117     debugPrint("\n Moving: " + source + "\n to " + target + "\n")
118     move(source,target)
119     elif not exists(source):
120     print ' ERROR: the source ('+source+') does not exist.'
121     elif exists(target):
122     print ' ERROR: the target ('+target+') exists already.'
123     else:
124     print ' ERROR: hmmm.... what is wrong here?'