ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/yiiyama/Toolset/scripts/arguments2json.py
Revision: 1.2
Committed: Fri Feb 8 21:24:23 2013 UTC (12 years, 2 months ago) by yiiyama
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +6 -6 lines
Log Message:
substituted split() for partition()

File Contents

# User Rev Content
1 yiiyama 1.1 #!/usr/bin/env python
2    
3     from optparse import OptionParser
4     from xml.dom.minidom import parseString
5    
6     parser = OptionParser()
7     parser.add_option("-f", "--file", dest="filename", help="list of job numbers", metavar="FILE")
8    
9     (options, args) = parser.parse_args()
10    
11     jobNumbers = []
12    
13     if options.filename:
14     filelist = file(options.filename, "r")
15     for f in filelist:
16     jobNumbers.append(f.strip())
17    
18     filelist.close()
19    
20     source = file(args[0])
21     else:
22     jobNumbers = args[0].split(',')
23     source = file(args[1])
24    
25     xmlStr = source.read()
26    
27     source.close()
28    
29     lumilist = dict()
30    
31     dom = parseString(xmlStr)
32    
33     jobTags = dom.getElementsByTagName('Job')
34    
35     for tag in jobTags:
36     process = False
37     for i in range(tag.attributes.length):
38     attr = tag.attributes.item(i)
39     if attr.name == 'JobID' and attr.value in jobNumbers:
40     process = True
41     jobNumbers.remove(attr.value)
42     elif attr.name == 'Lumis':
43     xmlLumis = attr.value
44    
45     if not process:
46     continue
47    
48     runLumiBlocks = xmlLumis.split(',')
49    
50     for block in runLumiBlocks:
51     if '-' in block:
52 yiiyama 1.2 ends = block.split('-')
53     run = ends[0].split(':')[0]
54     begin = int(ends[0].split(':')[1])
55     end = int(ends[1].split(':')[1]) + 1
56 yiiyama 1.1 else:
57 yiiyama 1.2 run = block.split(':')[0]
58     begin = int(block.split(':')[1])
59 yiiyama 1.1 end = begin + 1
60    
61     if run not in lumilist:
62     lumilist[run] = list()
63    
64     for l in range(begin, end):
65     lumilist[run].append(l)
66    
67     jsonTxt = "{"
68    
69     runs = lumilist.keys()
70     runs.sort()
71    
72     for run in runs:
73     lumis = lumilist[run]
74     if len(lumis) == 0:
75     continue
76    
77     lumis.sort()
78    
79     jsonTxt += '"' + str(run) + '": [[' + str(lumis[0]) + ', '
80    
81     l = lumis[0] - 1
82     for lumi in lumis:
83     if lumi != l + 1:
84     jsonTxt += str(l) + '], [' + str(lumi) + ', '
85    
86     l = lumi
87    
88     jsonTxt += str(lumis[len(lumis) - 1]) + ']], '
89    
90     jsonTxt = jsonTxt.rstrip(', ')
91     jsonTxt += "}"
92    
93     print jsonTxt
94