ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitProd/Processing/bin/sites.py
Revision: 1.4
Committed: Tue Feb 28 11:54:36 2012 UTC (13 years, 2 months ago) by paus
Content type: text/x-python
Branch: MAIN
CVS Tags: Mit_031, Mit_030, Mit_029c, Mit_029b, Mit_030_pre1, Mit_029a, Mit_029, Mit_029_pre1, Mit_028a, Mit_028, Mit_027a, Mit_027, Mit_026, Mit_025e, Mit_025d
Changes since 1.3: +3 -0 lines
Log Message:
Last updates.

File Contents

# Content
1 #!/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 usage += " [ --dbs=<name> ]\n"
10 usage += " --help\n"
11
12 # Define the valid options which can be specified and check out the command line
13 valid = ['block=','dbs=','help']
14 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 block = None
26 dbs = ''
27
28 # Read new values from the command line
29 for opt, arg in opts:
30 if opt == "--help":
31 print usage
32 sys.exit(0)
33 if opt == "--block":
34 block = arg
35 if opt == "--dbs":
36 dbs = arg
37
38 # Deal with obvious problems
39 if block == None:
40 cmd = "--block= required parameter not provided."
41 raise RuntimeError, cmd
42
43 #---------------------------------------------------------------------------------------------------
44 # main
45 #---------------------------------------------------------------------------------------------------
46 # find relevant site for this block
47 cmd = "dbs search "
48 if dbs != '':
49 cmd += " --url=" + dbs
50 cmd += " --query=\"find site where block=" + block + "\""
51 cmd += "| grep -v DBS | grep \\\."
52 sites = []
53 siteText = ''
54 for line in os.popen(cmd).readlines():
55 line = line[:-1]
56 sites.append(line)
57 if siteText != '':
58 siteText += ','
59 siteText += line
60
61 if siteText[0] == ',':
62 siteText = siteText[1:]
63
64 print siteText