"""Generates HTML page containing the testresults""" from testsuite_common import Result, processLogLine, getLastTwoLines from runtests import parse_testconfig import os import sys from datetime import datetime, timedelta HTML_HEADING = """
| Date | Time | Testname | Revision | Branch | Time | Prevtime | Prevrev | Change (%) | Time (Basebranch) | Change (%, Basebranch) | Time (Days -2) | Change (%, Days -2) | Time (Days -3) | Change (%, Days -3) | Time (Days -4) | Change (%, Days -4) | Time (Days -5) | Change (%, Days -5) | Time (Days -6) | Change (%, Days -6) | Time (Days -7) | Change (%, Days -7) | Time (Days -14) | Change (%, Days -14) | Time (Years -1) | Change (%, Years -1) | ' + str(resline.previous) + ' | ' if resline.percentage > 0.05: #If we have improvement of more than 5% cur_html = cur_html + '' + str(resline.percentage) + ' | ' elif resline.percentage < -0.05: #We have a regression of more than 5% cur_html = cur_html + '' + str(resline.percentage) + ' | ' else: cur_html = cur_html + '' + str(resline.percentage) + ' | ' return cur_html def compare_rev(filename, rev1, rev2, branch1=False, branch2=False): """Compare the test results of two lines. We can specify either a revision or a branch for comparison. The first rev should be the base version and the second revision should be the later version""" #In the log file the index of the revision is 2 but the index of #the branch is 12. Alternate those depending on whether we are looking #for a specific revision or branch. firstidx = 2 secondidx = 2 if branch1 == True: firstidx = 12 if branch2 == True: secondidx = 12 rev1line = '' rev2line = '' resfile = open(filename, 'r') for line in resfile: if rev1 == line.split()[firstidx]: rev1line = line elif rev2 == line.split()[secondidx]: rev2line = line if rev1line != '' and rev2line != '': break resfile.close() if rev1line == '': raise ValueError('Revision ' + rev1 + " was not found!") if rev2line == '': raise ValueError('Revision ' + rev2 + " was not found!") logLine1 = processLogLine(rev1line) logLine2 = processLogLine(rev2line) res = Result(logLine1.testname, logLine1.real, logLine2.real,\ logLine2.revision, logLine2.branch, logLine1.revision, logLine1.branch) return res def produce_html(path, global_config): """Produces html file for the report.""" html = '' #The table HTML for filenam in os.listdir(global_config.testlogs): #Generate html for the newest two lines #Get the lines from the config file (ll1, ll2) = getLastTwoLines(filenam, global_config.testlogs) logLine1 = processLogLine(ll1) logLine2 = processLogLine(ll2) #This is the life from the latest revision #Generate html res1 = Result(logLine1.testname, logLine1.real, logLine2.real,\ logLine2.revision, logLine2.branch, logLine1.revision, logLine1.branch) html = html + '
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ' + logLine2.date + ' | ' + logLine2.time + ' | ' +\ res1.testname + ' | ' + res1.revision[:10] + ' | ' + res1.branch + ' | ' +\ str(res1.current) + ' | ' + str(res1.previous) + ' | ' + res1.prevrev[:10] + ' | ' #Add fancy colours depending on the change if res1.percentage > 0.05: #If we have improvement of more than 5% html = html + '' + str(res1.percentage) + ' | ' elif res1.percentage < -0.05: #We have a regression of more than 5% html = html + '' + str(res1.percentage) + ' | ' else: html = html + '' + str(res1.percentage) + ' | ' #Get comparison against the base version filenam = global_config.testlogs + '/' + filenam #Get proper directory res2 = compare_rev(filenam, global_config.basebranch, res1.revision, branch1=True) html = html + '' + str(res2.previous) + ' | ' #Add fancy colours depending on the change if res2.percentage > 0.05: #If we have improvement of more than 5% html = html + '' + str(res2.percentage) + ' | ' elif res2.percentage < -0.05: #We have a regression of more than 5% html = html + '' + str(res2.percentage) + ' | ' else: html = html + '' + str(res2.percentage) + ' | ' #Add extra dates comparison dating from the beginning of time if they exist past_dates = list(range(2, 8)) past_dates.append(14) past_dates.append(365) # Get the 1 year ago day linesdict = gather_necessary_lines(filenam, logLine2.date) for days in past_dates: act_date = get_prev_days(logLine2.date, days) if linesdict[act_date][1] is not None: logline_date = linesdict[act_date][1] restemp = Result(logline_date.testname, logline_date.real, logLine2.real,\ logLine2.revision, logLine2.branch, logline_date.revision, logline_date.branch) html = html + append_date_to_table(restemp) else: html = html + 'N/A | N/A | ' html = html + '