1 |
paus |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
#---------------------------------------------------------------------------------------------------
|
3 |
|
|
# Script to convert a simple directoryinto the full srm target URL.
|
4 |
|
|
#
|
5 |
|
|
# Author: C.Paus (Oct 05, 2011)
|
6 |
|
|
#---------------------------------------------------------------------------------------------------
|
7 |
|
|
import getopt,sys,os,srm
|
8 |
|
|
|
9 |
|
|
#===================================================================================================
|
10 |
|
|
# Main starts here
|
11 |
|
|
#===================================================================================================
|
12 |
|
|
# Define string to explain usage of the script
|
13 |
|
|
usage = " Usage: getsrm --debug\n"
|
14 |
|
|
usage += " --help\n"
|
15 |
|
|
|
16 |
|
|
# Define the valid options which can be specified and check out the command line
|
17 |
|
|
valid = ['debug','help']
|
18 |
|
|
try:
|
19 |
|
|
opts, args = getopt.getopt(sys.argv[1:], "", valid)
|
20 |
|
|
except getopt.GetoptError, ex:
|
21 |
|
|
print usage
|
22 |
|
|
print str(ex)
|
23 |
|
|
sys.exit(1)
|
24 |
|
|
|
25 |
|
|
# --------------------------------------------------------------------------------------------------
|
26 |
|
|
# Get all parameters for the production
|
27 |
|
|
# --------------------------------------------------------------------------------------------------
|
28 |
|
|
# Set defaults for each option
|
29 |
|
|
debug = False
|
30 |
|
|
# Read new values from the command line
|
31 |
|
|
for opt, arg in opts:
|
32 |
|
|
if opt == '--help':
|
33 |
|
|
print usage
|
34 |
|
|
sys.exit(0)
|
35 |
|
|
if opt == '--debug':
|
36 |
|
|
debug = True
|
37 |
|
|
|
38 |
|
|
# Test whether the directory exists and then proceed
|
39 |
|
|
for dir in sys.argv[1:]:
|
40 |
|
|
if dir[:2] == "--":
|
41 |
|
|
continue
|
42 |
|
|
if debug:
|
43 |
|
|
print "\nProcessing: " + dir + "\n"
|
44 |
|
|
storageUrl = srm.convertToUrl(dir,debug)
|
45 |
|
|
|
46 |
|
|
print storageUrl
|