1#!/usr/bin/env python 2import json 3import sys 4 5if len(sys.argv) > 1: 6 filename = sys.argv[1] 7else: 8 filename = './result.json' 9 10 11def get_key(item): 12 ds = item[0].split('_') 13 no = int(ds[1]) * 10000 + int(ds[2]) * 100 + int(ds[3]) 14 ro = ds[0] 15 return '%d-%s' % (no, ro) 16 17 18result = json.load(open(filename, 'r')) 19o = open('./result.csv', 'w') 20o.write('Case,Status,Started,Stopped,Reason\n') 21for k, v in sorted(result.items(), key=get_key): 22 o.write('%s,%s,%s,%s,%s\n' % ( 23 k, 24 (v['passed'] and 'Pass') or 'Fail', 25 v['started'], 26 v['stopped'], 27 (v['error'] or '').replace('\n', ' '), 28 )) 29