File size: 1,601 Bytes
6c50d1f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | import argparse
import os
import json
import time
def get_coverage_logs(path):
files = os.listdir(path)
return [path + "/" + f for f in files]
def read_data(path=""):
with open(path, 'r', encoding="utf-8") as jsonfile:
data = jsonfile.read()
obj = json.loads(data)
return obj
def run_single(folder, result={}):
logs = (get_coverage_logs(folder))
for log in logs:
print("read", log)
data = read_data(log)
for file_name in data:
if not (file_name in result):
result[file_name] = list()
for line in data[file_name]:
if line in result[file_name]:
continue
result[file_name].append(line)
os.unlink(log)
line_count = 0
for file_name in result:
if file_name == "line_count":
continue
line_count += len(result[file_name])
result["line_count"] = line_count
print("total line count", line_count)
def main(args):
coverage_folder = args.c
output_file = args.o
result = {}
while True:
print("read from", coverage_folder)
print("write to", output_file)
run_single(coverage_folder, result)
with open(output_file, 'w') as data:
json.dump(result, data)
time.sleep(3)
if __name__ == '__main__':
args = argparse.ArgumentParser()
args.add_argument('-c', default="coverage", help="coverage folder")
args.add_argument('-o', default="coverage.json", help="output file, default coverage.json")
main(args.parse_args())
|