File: submitperftest.in

package info (click to toggle)
xapian-core 1.4.3-2~bpo8+1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 21,224 kB
  • sloc: cpp: 113,806; ansic: 8,723; sh: 4,433; perl: 836; makefile: 567; tcl: 317; python: 40
file content (82 lines) | stat: -rwxr-xr-x 2,506 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
#
# Copyright 2008 Lemur Consulting Ltd
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA
"""Run a performance test, and submit the results to the public archive.

Usage:

submitperftest

"""

import sys
sys.path.insert(0, r"@srcdir@")

import os
import re
import urllib2
import urllib2_file

# URL to send submissions to.
submission_path = "http://tartarus.org/richard/perftest/upload.cgi"

class fdwrapper:
    def __init__(self, fd, callback):
        self.fd = fd

    def __getattr__(self, attr):
        print "getattr", attr
        return getattr(self.fd, attr)

def submit_perftest(filepath):
    """Send the performance test results in a file to the server.

    Returns a code number which can be used to find the results on the server
    again.

    """
    fd = open(filepath, "r")
    req = urllib2.Request(submission_path, {'file': fd})
    try:
        response = urllib2.urlopen(req)
    except urllib2.HTTPError, e:
        print "HTTPError: ", e.message, ": ", e.strerror
        return

    resdata = response.read()
    g_begin = re.search('<!-- MSG_BEGIN[^\n]*\n', resdata)
    g_end = re.search('MSG_END -->\n', resdata)
    if g_begin is None or g_end is None:
        print "Invalid return from submission server - test may not have been uploaded successfully"
        return
    lines = resdata[g_begin.end():g_end.start()].strip().split('\n')
    if len(lines) < 2:
        print "Unexpected return from submission server - test may not have been uploaded successfully"
        return
    if lines[0] != 'OK':
        print "Unsuccessful submission: server said:\n" + '\n'.join(lines[1:])
        return
    print "Successful submission: server said:\n"
    print '\n'.join(lines[1:])


def main():
    submit_perftest(os.path.join(r"@builddir@", "perflog.xml"))

if __name__ == '__main__':
    main()