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
17 from datetime
import datetime
20 executablePath
= "C:\\cygwin\\tmp\\test\\"
21 configFilePath
= "C:\\mozilla\\testing\\performance\\talos\\"
23 # TODO: maybe this should be searched for?
25 #masterIniSubpath = path.join("firefox", "extensions", "talkback@mozilla.org",
26 # "components", "master.ini")
28 masterIniSubpath
= path
.join("firefox", "components", "talkback", "master.ini")
30 # masterIniSubpath = path.join("*.app", "Contents", "MacOS", "extensions",
31 # "talkback@mozilla.org", "components",
32 # "talkback", "master.ini"
33 defaultTitle
= "qm-pxp01"
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
42 class PerfConfigurator
:
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
))
71 raise Configuration("Unable to open "
72 + path
.join(self
.exePath
, masterIniSubpath
))
73 masterContents
= master
.readlines()
75 reBuildid
= re
.compile('BuildID\s*=\s*"(\d{10})"')
76 for line
in masterContents
:
77 match
= re
.match(reBuildid
, line
)
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
()
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()
97 buildidString
= "'" + str(self
.buildid
) + "'"
100 if 'firefox:' in line
:
101 newline
= 'firefox: ' + self
.exePath
103 newline
= 'title: ' + self
.title
104 if self
.testDateFromBuildId
:
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
)
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
):
145 exePath
= executablePath
146 configPath
= configFilePath
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
:
165 for option
, value
in opts
:
166 if option
in ("-v", "--verbose"):
168 if option
in ("-h", "--help"):
169 raise Usage(help_message
)
170 if option
in ("-e", "--executablePath"):
172 if option
in ("-c", "--configFilePath"):
174 if option
in ("-t", "--title"):
176 if option
in ("-b", "--branch"):
178 if option
in ("-o", "--output"):
180 if option
in ("-i", "--id"):
182 if option
in ("-d", "--testDate"):
186 print >> sys
.stderr
, sys
.argv
[0].split("/")[-1] + ": " + str(err
.msg
)
187 print >> sys
.stderr
, "\t for help use --help"
190 configurator
= PerfConfigurator(title
=title
,
191 executablePath
=exePath
,
192 configFilePath
=configPath
,
199 configurator
.writeConfigFile()
200 except Configuration
, err
:
201 print >> sys
.stderr
, sys
.argv
[0].split("/")[-1] + ": " + str(err
.msg
)
206 if __name__
== "__main__":