ia64/xen-unstable

view tools/xm-test/lib/XmTestReport/Report.py @ 7757:139aabe357a4

Various chmod a+x.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Thu Nov 10 12:00:09 2005 +0100 (2005-11-10)
parents ecb5997f7b25
children
line source
1 #!/usr/bin/python
3 """
4 Report.py - Handles the coordination of xm-test xml-reporting modules
6 Copyright (C) International Business Machines Corp., 2005
7 Author: Dan Smith <danms@us.ibm.com>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; under version 2 of the License.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 """
24 import OSReport
25 import ProgReport
26 import ResultReport
27 import utils
29 import sys
30 import os
31 import xml.dom.minidom
32 import httplib
33 import urllib
35 #REPORT_HOST = "xmtest-dev.dague.org"
36 REPORT_HOST = "xmtest.dague.org"
37 REPORT_URL = "/cgi-bin/report-results";
39 class XmTestReport:
41 def __init__(self, files):
42 self.files = files
44 def __getContactInfo(self):
45 if os.access("contact_info", os.R_OK):
46 c = file("contact_info")
47 line = c.readline()
48 line = line.strip()
49 return line
50 else:
51 return "nobody@nowhere.com"
53 def __stringify(self, fileName):
54 f = file(fileName)
55 str = f.read()
56 f.close()
58 return str
60 def __str__(self):
61 string = "<testname>xm-test</testname>\n"
62 string += "<user>%s</user>\n" % self.__getContactInfo()
64 for f in self.files:
65 string += self.__stringify(f)
67 return string
69 # Taken from example in Python Cookbook
70 def encodeForm(fieldList):
71 body = []
72 boundary = "-------XmTestReportingXML"
74 for name in fieldList.keys():
75 body.append('--' + boundary)
76 body.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (name, "%s.txt" % name))
77 body.append('Content-Type: text/plain')
78 body.append('')
79 body.append(fieldList[name])
81 body.append('')
82 body.append("--" + boundary + "--")
83 body.append('')
85 textBody = "\r\n".join(body)
87 return 'multipart/form-data; boundary=%s' % boundary, textBody
89 def postResults(results):
90 conn = httplib.HTTPConnection(REPORT_HOST)
92 type, body = encodeForm({"log" : results})
94 headers = {"content-type" : type}
96 # DEBUG OUTPUT
97 # print "BODY\n%s\nBODY\n" % body
98 # print "%s\n" % type
99 # print headers
101 conn.request("POST", REPORT_URL, body, headers)
103 resp = conn.getresponse()
104 if resp.status == 200:
105 print >>sys.stderr, "Your results have been submitted successfully!"
106 else:
107 print >>sys.stderr, "Unable to submit results:"
108 print >>sys.stderr, "[http://%s%s] said %i: %s" % (REPORT_HOST,
109 REPORT_URL,
110 resp.status,
111 resp.reason)
113 data = resp.read()
114 print >>sys.stderr, data
116 if __name__ == "__main__":
118 if len(sys.argv) <= 1:
119 print "Usage: Report.py [opt] <outputfiles...>"
120 print "Where:"
121 print "-d : don't submit, just dump XML"
122 print "-D : do submit and dump XML"
123 sys.exit(1)
125 submit = True
126 dump = False
127 files = []
129 for a in sys.argv[1:]:
130 if a == "-d":
131 submit = False
132 dump = True
133 elif a == "-D":
134 dump = True
135 submit = True
137 else:
138 if not os.access(a, os.R_OK):
139 print "Unable to access file: %s" % a
140 sys.exit(1)
141 else:
142 files.append(a)
144 report = XmTestReport(files)
146 xmlout = "<xml>\n%s</xml>\n" % report
148 if dump:
149 print xmlout
151 if submit:
152 postResults(xmlout)