ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/sites.py
Revision: 1.5
Committed: Fri Jul 26 14:53:30 2013 UTC (11 years, 9 months ago) by paus
Content type: text/x-python
Branch: MAIN
CVS Tags: Mit_032, HEAD
Changes since 1.4: +14 -2 lines
Log Message:
Updates

File Contents

# User Rev Content
1 paus 1.2 #!/usr/bin/env python
2     #---------------------------------------------------------------------------------------------------
3     # Simple interface to command line DBS to prepare my crabTask input files.
4     #---------------------------------------------------------------------------------------------------
5     import os,sys,types,string,getopt
6    
7     # Define string to explain usage of the script
8     usage = "Usage: site.py --block=<name>\n"
9 paus 1.3 usage += " [ --dbs=<name> ]\n"
10 paus 1.2 usage += " --help\n"
11    
12     # Define the valid options which can be specified and check out the command line
13 paus 1.3 valid = ['block=','dbs=','help']
14 paus 1.2 try:
15     opts, args = getopt.getopt(sys.argv[1:], "", valid)
16     except getopt.GetoptError, ex:
17     print usage
18     print str(ex)
19     sys.exit(1)
20    
21     # --------------------------------------------------------------------------------------------------
22     # Get all parameters for the production
23     # --------------------------------------------------------------------------------------------------
24     # Set defaults for each option
25 paus 1.5 block = None
26     dbs = ''
27     private = False
28 paus 1.2
29     # Read new values from the command line
30     for opt, arg in opts:
31     if opt == "--help":
32     print usage
33     sys.exit(0)
34     if opt == "--block":
35     block = arg
36 paus 1.3 if opt == "--dbs":
37     dbs = arg
38 paus 1.2
39     # Deal with obvious problems
40     if block == None:
41     cmd = "--block= required parameter not provided."
42     raise RuntimeError, cmd
43    
44 paus 1.5 # is it a private production
45     f = block.split('#')
46     if f[1] == "00000000-0000-0000-0000-000000000000":
47     private = True
48     #print ' Attention -- private dataset identified.'
49    
50 paus 1.2 #---------------------------------------------------------------------------------------------------
51     # main
52     #---------------------------------------------------------------------------------------------------
53 paus 1.5 # handle private production first
54     if private:
55     print block + ' : ' + 'se01.cmsaf.mit.edu'
56     sys.exit()
57    
58 paus 1.2 # find relevant site for this block
59 paus 1.3 cmd = "dbs search "
60     if dbs != '':
61     cmd += " --url=" + dbs
62     cmd += " --query=\"find site where block=" + block + "\""
63 paus 1.2 cmd += "| grep -v DBS | grep \\\."
64     sites = []
65     siteText = ''
66     for line in os.popen(cmd).readlines():
67     line = line[:-1]
68     sites.append(line)
69     if siteText != '':
70     siteText += ','
71     siteText += line
72    
73 paus 1.4 if siteText[0] == ',':
74     siteText = siteText[1:]
75    
76 paus 1.2 print siteText