3 # Copyright 2008 Lemur Consulting Ltd
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 """Run a performance test, and submit the results to the public archive.
28 sys
.path
.insert(0, r
"@srcdir@")
35 # URL to send submissions to.
36 submission_path
= "http://tartarus.org/richard/perftest/upload.cgi"
39 def __init__(self
, fd
, callback
):
42 def __getattr__(self
, attr
):
44 return getattr(self
.fd
, attr
)
46 def submit_perftest(filepath
):
47 """Send the performance test results in a file to the server.
49 Returns a code number which can be used to find the results on the server
53 fd
= open(filepath
, "r")
54 req
= urllib2
.Request(submission_path
, {'file': fd
})
56 response
= urllib2
.urlopen(req
)
57 except urllib2
.HTTPError
, e
:
58 print "HTTPError: ", e
.message
, ": ", e
.strerror
61 resdata
= response
.read()
62 g_begin
= re
.search('<!-- MSG_BEGIN[^\n]*\n', resdata
)
63 g_end
= re
.search('MSG_END -->\n', resdata
)
64 if g_begin
is None or g_end
is None:
65 print "Invalid return from submission server - test may not have been uploaded successfully"
67 lines
= resdata
[g_begin
.end():g_end
.start()].strip().split('\n')
69 print "Unexpected return from submission server - test may not have been uploaded successfully"
72 print "Unsuccessful submission: server said:\n" + '\n'.join(lines
[1:])
74 print "Successful submission: server said:\n"
75 print '\n'.join(lines
[1:])
79 submit_perftest(os
.path
.join(r
"@builddir@", "perflog.xml"))
81 if __name__
== '__main__':