#!/usr/bin/python """ This script is used to reveive the test result. It will display the result in the table format on a web page, and is able to save the result data as json format to a file under the /tmp/methanol directory. HOW TO USE: 1. copy this script to the cgi-bin directory of your web server on my ubuntu, will do like this: cp save_methanol_data.py /usr/lib/cgi-bin/ 2. make this script executable chmod +x /usr/lib/cgi-bin/save_methanol_data.py 3. add the url of this script to the test url, like: http://localhost/methanol/fire.html?reportToUrl=/cgi-bin/save_methanol_data.py if want to save the result to a file, we can do like: http://localhost/methanol/fire.html?reportToUrl=/cgi-bin/save_methanol_data.py%3Fsave2file=res.json then when the test finished, there will be a file /tmp/methanol/res.json generated. or you can specified the save2file with an absolute path. """ import cgitb import cgi import os import simplejson as json cgitb.enable() print "Content-Type: text/html;" print print '''
''' FLAG_SAVE_TO_FILE = 'save2file' #set the default directory to save the result file #when the passed save2file is a relative path(like just a name) SAVE_DIR = '/tmp/methanol' f = cgi.FieldStorage() save_file_path = f.getvalue(FLAG_SAVE_TO_FILE) # for windows, I think we can use like: # if not save_file_path[0] == '/' and not save_file_path[1:3] == ':\\': # but because I don't have an windows environment, # so comment here for reference when necessary if save_file_path: if not save_file_path[0] == '/' : save_file_path=os.path.join(SAVE_DIR, save_file_path) SAVE_DIR = os.path.dirname(save_file_path) save_file = os.path.basename(save_file_path) else: save_file = None test_results = [] print '''test_case_id | average(ms) | deviate average(%) | |||
---|---|---|---|---|---|
%s | ' % key print ' | %s | ' % average print ' | %s | ' % average_deviate print ' |