ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/makedir
Revision: 1.3
Committed: Wed Oct 19 10:43:11 2011 UTC (13 years, 6 months ago) by paus
Branch: MAIN
CVS Tags: Mit_025c_branch2, Mit_025c_branch1, Mit_029_pre1, Mit_028a, Mit_025c_branch0, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d, Mit_025c, Mit_025b, Mit_025a
Branch point for: Mit_025c_branch
Changes since 1.2: +3 -3 lines
Log Message:
Updates realted to hadoop move of Tier-2.

File Contents

# User Rev Content
1 paus 1.1 #!/usr/bin/env python
2     #---------------------------------------------------------------------------------------------------
3     # Script to make a directory for the production
4     #
5     # Author: C.Paus (Jan 08, 2011)
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     def exists(target):
22     storagePath = '/srm/managerv2?SFN='
23     if re.search('/castor/cern.ch/',target):
24     debugPrint(' Identified castor file')
25     storageEle = 'srm-cms.cern.ch'
26     storageUrl = 'srm://' + storageEle + ':8443' + storagePath + target
27     cmd = 'srmls ' + storageUrl + ' >& /dev/null'
28     elif re.search('/pnfs/cmsaf.mit.edu/',target):
29     debugPrint(' Identified tier-2 file')
30     storageEle = 'se01.cmsaf.mit.edu'
31     storageUrl = 'srm://' + storageEle + ':8443' + storagePath + target
32     cmd = 'srmls ' + storageUrl + ' >& /dev/null'
33 paus 1.2 elif re.search('/mnt/hadoop/cms/store/',target):
34     debugPrint(' Identified tier-2 hadoop file')
35     storagePath = '/srm/v2/server?SFN='
36 paus 1.3 storageEle = 'se01.cmsaf.mit.edu'
37 paus 1.2 storageUrl = 'srm://' + storageEle + ':8443' + storagePath + target
38     cmd = 'srmls ' + storageUrl + ' >& /dev/null'
39 paus 1.1 else:
40     debugPrint(' Identified a normal directory')
41     cmd = 'ls -1 ' + target + ' >& /dev/null'
42    
43     status = os.system(cmd)
44 paus 1.3 debugPrint(' Status: %d (for: %s)' %(status,cmd))
45 paus 1.1
46     return (status == 0)
47    
48     def makeDir(target):
49     storagePath = '/srm/managerv2?SFN='
50     if re.search('/castor/cern.ch/',target):
51     debugPrint(' Identified castor file')
52     storageEle = 'srm-cms.cern.ch'
53     storageUrl = 'srm://' + storageEle + ':8443' + storagePath + target
54     cmd = 'srmmkdir ' + storageUrl + ' >& /dev/null' + \
55     '; srm-set-permissions -type=ADD -owner=RWX -group=RWX -other=RWX ' + storageUrl
56     elif re.search('/pnfs/cmsaf.mit.edu/',target):
57     debugPrint(' Identified tier-2 file')
58     storageEle = 'se01.cmsaf.mit.edu'
59     storageUrl = 'srm://' + storageEle + ':8443' + storagePath + target
60     cmd = 'srmmkdir ' + storageUrl + ' >& /dev/null' + \
61     '; srm-set-permissions -type=ADD -owner=RWX -group=RWX -other=RWX ' + storageUrl
62 paus 1.2 elif re.search('/mnt/hadoop/cms/store/',target):
63     debugPrint(' Identified tier-2 hadoop file')
64     storagePath = '/srm/v2/server?SFN='
65 paus 1.3 storageEle = 'se01.cmsaf.mit.edu'
66 paus 1.2 storageUrl = 'srm://' + storageEle + ':8443' + storagePath + target
67     cmd = 'srmmkdir ' + storageUrl + ' >& /dev/null' + \
68     '; srm-set-permissions -type=ADD -owner=RWX -group=RWX -other=RWX ' + storageUrl
69 paus 1.1 else:
70     debugPrint(' Identified a normal directory')
71     cmd = 'mkdir ' + target
72    
73     # ready to perform the requested operation
74     debugPrint(' -> makedir with: ' + cmd)
75     status = 0
76     if exe == 1:
77     status = os.system(cmd)
78    
79     return status
80    
81     #===================================================================================================
82     # Main starts here
83     #===================================================================================================
84     # Define string to explain usage of the script
85     usage = "Usage: makedir <target>"
86     usage += " --exe\n"
87     usage += " --debug\n"
88     usage += " --help\n"
89    
90     # Define the valid options which can be specified and check out the command line
91     valid = ['exe','debug','help']
92     try:
93     opts, args = getopt.getopt(sys.argv[1:], "", valid)
94     except getopt.GetoptError, ex:
95     print usage
96     print str(ex)
97     sys.exit(1)
98    
99     # --------------------------------------------------------------------------------------------------
100     # Get all parameters for the production
101     # --------------------------------------------------------------------------------------------------
102     # Set defaults for each option
103     debug = 0
104     exe = 0
105    
106     # Read new values from the command line
107     for opt, arg in opts:
108     #print ' OPT , ARG: ' + opt + ' ' + arg
109     if opt == '--help':
110     print usage
111     sys.exit(0)
112     elif opt == '--debug':
113     debug = 1
114     elif opt == '--exe':
115     exe = 1
116    
117     newArgv = []
118     for arg in sys.argv[1:]:
119     #print ' ARG: ' + arg
120     if arg[:2] == "--":
121     continue
122     else:
123     newArgv.append(arg)
124    
125     # cleanup the target
126     target = clean(newArgv[0])
127    
128     # Test whether the target exists and make it if required
129     if exists(target):
130     debugPrint("\n No action required, target exists already: %s\n"%target)
131     elif not exists(target):
132     print ' make directory ('+target+').'
133     makeDir(target)