Bug 460926 A11y hierachy is broken on Ubuntu 8.10 (GNOME 2.24), r=Evan.Yan sr=roc
[wine-gecko.git] / testing / performance / talos / PerfConfigurator.py
blob12f6e0ab4de7f8daeb7eadbd5691ac80a59f76ac
1 #!/usr/bin/env python
2 # encoding: utf-8
3 """
4 PerfConfigurator.py
6 Created by Rob Campbell on 2007-03-02.
7 Modified by Rob Campbell on 2007-05-30
8 Modified by Rob Campbell on 2007-06-26 - added -i buildid option
9 Modified by Rob Campbell on 2007-07-06 - added -d testDate option
10 Modified by Ben Hearsum on 2007-08-22 - bugfixes, cleanup, support for multiple platforms. Only works on Talos2
11 """
13 import sys
14 import getopt
15 import re
16 import time
17 from datetime import datetime
18 from os import path
20 executablePath = "C:\\cygwin\\tmp\\test\\"
21 configFilePath = "C:\\mozilla\\testing\\performance\\talos\\"
23 # TODO: maybe this should be searched for?
24 # For Windows
25 #masterIniSubpath = path.join("firefox", "extensions", "talkback@mozilla.org",
26 # "components", "master.ini")
27 # For Linux
28 masterIniSubpath = path.join("firefox", "components", "talkback", "master.ini")
29 # For OS X
30 # masterIniSubpath = path.join("*.app", "Contents", "MacOS", "extensions",
31 # "talkback@mozilla.org", "components",
32 # "talkback", "master.ini"
33 defaultTitle = "qm-pxp01"
35 help_message = '''
36 This is the buildbot performance runner's YAML configurator.bean
38 USAGE: python PerfConfigurator.py -e executablePath -c configFilePath
39 -b branchid -t title -o output -i buildid -d
40 '''
42 class PerfConfigurator:
43 exePath = ""
44 configPath = ""
45 outputName = ""
46 title = ""
47 branch = ""
48 buildid = ""
49 currentDate = ""
50 verbose = False
51 testDateFromBuildId = False
53 def _dumpConfiguration(self):
54 """dump class configuration for convenient pickup or perusal"""
55 print "Writing configuration:"
56 print " - title = " + self.title
57 print " - executablePath = " + self.exePath
58 print " - configPath = " + self.configPath
59 print " - outputName = " + self.outputName
60 print " - branch = " + self.branch
61 print " - buildid = " + self.buildid
62 print " - currentDate = " + self.currentDate
64 def _getCurrentDateString(self):
65 currentDateTime = datetime.now()
66 return currentDateTime.strftime("%Y%m%d_%H%M")
68 def _getCurrentBuildId(self):
69 master = open(path.join(self.exePath, masterIniSubpath))
70 if not master:
71 raise Configuration("Unable to open "
72 + path.join(self.exePath, masterIniSubpath))
73 masterContents = master.readlines()
74 master.close()
75 reBuildid = re.compile('BuildID\s*=\s*"(\d{10})"')
76 for line in masterContents:
77 match = re.match(reBuildid, line)
78 if match:
79 return match.group(1)
80 raise Configuration("BuildID not found in "
81 + path.join(self.exePath, masterIniSubpath))
83 def _getTimeFromBuildId(self):
84 buildIdTime = time.strptime(self.buildid, "%Y%m%d%H")
85 return time.strftime("%a, %d %b %Y %H:%M:%S GMT", buildIdTime)
87 def writeConfigFile(self):
88 configFile = open(path.join(self.configPath, "sample.config"))
89 self.currentDate = self._getCurrentDateString()
90 if not self.buildid:
91 self.buildid = self._getCurrentBuildId()
92 if not self.outputName:
93 self.outputName = self.currentDate + "_config.yml"
94 destination = open(self.outputName, "w")
95 config = configFile.readlines()
96 configFile.close()
97 buildidString = "'" + str(self.buildid) + "'"
98 for line in config:
99 newline = line
100 if 'firefox:' in line:
101 newline = 'firefox: ' + self.exePath
102 if 'title:' in line:
103 newline = 'title: ' + self.title
104 if self.testDateFromBuildId:
105 newline += '\n'
106 newline += 'testdate: "%s"\n' % self._getTimeFromBuildId()
107 if 'buildid:' in line:
108 newline = 'buildid: ' + buildidString
109 if 'testbranch' in line:
110 newline = 'branch: ' + self.branch
111 destination.write(newline)
112 destination.close()
113 if self.verbose:
114 self._dumpConfiguration()
116 def __init__(self, **kwargs):
117 if 'title' in kwargs:
118 self.title = kwargs['title']
119 if 'branch' in kwargs:
120 self.branch = kwargs['branch']
121 if 'executablePath' in kwargs:
122 self.exePath = kwargs['executablePath']
123 if 'configFilePath' in kwargs:
124 self.configPath = kwargs['configFilePath']
125 if 'outputName' in kwargs:
126 self.outputName = kwargs['outputName']
127 if 'buildid' in kwargs:
128 self.buildid = kwargs['buildid']
129 if 'verbose' in kwargs:
130 self.verbose = kwargs['verbose']
131 if 'testDate' in kwargs:
132 self.testDateFromBuildId = kwargs['testDate']
135 class Configuration(Exception):
136 def __init__(self, msg):
137 self.msg = "ERROR: " + msg
139 class Usage(Exception):
140 def __init__(self, msg):
141 self.msg = msg
144 def main(argv=None):
145 exePath = executablePath
146 configPath = configFilePath
147 output = ""
148 title = defaultTitle
149 branch = ""
150 testDate = False
151 verbose = False
152 buildid = ""
154 if argv is None:
155 argv = sys.argv
156 try:
157 try:
158 opts, args = getopt.getopt(argv[1:], "hve:c:t:b:o:i:d",
159 ["help", "verbose", "executablePath=", "configFilePath=", "title=",
160 "branch=", "output=", "id=", "testDate"])
161 except getopt.error, msg:
162 raise Usage(msg)
164 # option processing
165 for option, value in opts:
166 if option in ("-v", "--verbose"):
167 verbose = True
168 if option in ("-h", "--help"):
169 raise Usage(help_message)
170 if option in ("-e", "--executablePath"):
171 exePath = value
172 if option in ("-c", "--configFilePath"):
173 configPath = value
174 if option in ("-t", "--title"):
175 title = value
176 if option in ("-b", "--branch"):
177 branch = value
178 if option in ("-o", "--output"):
179 output = value
180 if option in ("-i", "--id"):
181 buildid = value
182 if option in ("-d", "--testDate"):
183 testDate = True
185 except Usage, err:
186 print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
187 print >> sys.stderr, "\t for help use --help"
188 return 2
190 configurator = PerfConfigurator(title=title,
191 executablePath=exePath,
192 configFilePath=configPath,
193 buildid=buildid,
194 branch=branch,
195 verbose=verbose,
196 testDate=testDate,
197 outputName=output)
198 try:
199 configurator.writeConfigFile()
200 except Configuration, err:
201 print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
202 return 5
203 return 0
206 if __name__ == "__main__":
207 sys.exit(main())