forked from raoweijian/jacoco-diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·46 lines (35 loc) · 1.26 KB
/
main.py
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
#!/usr/bin/env python3
#coding=utf8
import os
import json
import sys
import re
import pprint
import shutil
import getopt
import argparse
from git import Repo
from diff_processor import DiffProcessor
def main(argv):
# 解析命令行参数
parser = argparse.ArgumentParser(description="计算增量覆盖率的工具")
parser.add_argument('-dir', type=str, help="工程根目录")
parser.add_argument('-old_version', type=str, default="HEAD~1", help='指定对比的版本号')
parser.add_argument('-module', type=str, help="需要处理的子模块")
opts = parser.parse_args(argv[1:])
if opts.dir is None or opts.module is None:
parser.print_help()
sys.exit()
# 获取增量覆盖率信息
processor = DiffProcessor(opts.dir, opts.old_version, opts.module)
diff_cov_info = processor.process_diff()
# 写入redis
job_name = argv[4]
build_id = argv[5]
key = "{}-{}".format(job_name, build_id)
# 拷贝 css 和图片资源
shutil.copy('diff.gif', os.path.join(opts.dir, opts.module, "target/site/jacoco/jacoco-resources"))
shutil.copy('report.css', os.path.join(opts.dir, opts.module, "target/site/jacoco/jacoco-resources"))
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))