import os
import sys
html_table_open = '''
| Virtual Machine |
Kind of test |
Result |
TXT Report |
Screenshot |
'''
html_table_closed = '
'
html_section = '''
| AV_NAME |
AV_KIND |
AV_RESULT |
txt report |
screenshot |
'''
def parse_results(filename):
success = []
errors = []
failed = []
with open(filename, 'rb') as f:
for l in f.readlines():
try:
e=eval(l)
for k in e:
j = k.split(",")
#print j
if "SUCCESS" in j[3] or "FAILED" in j[3]:
#j[0],j[1],j[3]
res = {}
'''
res['av'] = j[0][:-1]
res['kind'] = j[1]
'''
res['av'] = j[1]
res['kind'] = j[0]
res['result'] = j[3].split(":")[2][3:-2].replace("+","")
if "SUCCESS" in j[3]:
success.append(res)
else:
failed.append(res)
except:
if "ERROR" in l:
errors.append(l)
#print "failed: %s" % e
pass
return success,errors,failed
def add_header(name):
html_head = "%s
" % name
html_head += html_table_open
return html_head
def add_results(res):
html_results = ""
for s in res:
html_table = html_section
html_table = html_table.replace("AV_NAME",s['av'])
html_table = html_table.replace("AV_KIND",s['kind'])
html_table = html_table.replace("AV_RESULT",s['result'])
html_table = html_table.replace("AV_TXT_LINK","results_%s_%s.txt" % (s['av'],s['kind']) )
html_table = html_table.replace("AV_SCREEN_LINK","screenshot_%s_%s.png" % (s['av'],s['kind']) )
html_results += html_table
return html_results
def add_errors(errors):
html_errs = ""
for e in errors:
html_errs += e
return html_errs
def write_html_report(results, html_file_name):
success,errors,failed = results
with open(html_file_name, 'wb') as f:
f.write("")
f.write( add_header("Failed") )
f.write( add_results(failed) )
f.write( html_table_closed)
f.write( "Errors
")
f.write( add_errors(errors) )
f.write( add_header("Success") )
f.write( add_results(success) )
f.write( html_table_closed)
f.write("")
if __name__ == "__main__":
html_file_name = "/tmp/bozz.html"
results = parse_results("/tmp/bozz")
write_html_report(results, html_file_name)
.