forked from Tencent/CodeAnalysis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodecounttask.py
More file actions
54 lines (49 loc) · 2.3 KB
/
codecounttask.py
File metadata and controls
54 lines (49 loc) · 2.3 KB
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
# -*- encoding: utf-8 -*-
# Copyright (c) 2021-2025 Tencent
#
# This source code file is made available under MIT License
# See LICENSE for details
# ==============================================================================
"""
CodeCountTask
"""
import json
import logging
from node.localtask.requestmodify import RequestModify
from node.localtask.runtask import SingleTaskRuner
logger = logging.getLogger(__name__)
class CodeCountTask(object):
@staticmethod
def run_count_line_task(request_list, task_name_id_maps, job_id, scm_auth_info, token, server_url, source_dir,
scm_info, origin_os_env, create_from):
"""
统计代码行
:param request_list:
:return:
"""
request = request_list[0].copy() # 要用copy,以免影响原字典数据
request["task_name"] = "linecount"
request["processes"] = ["analyze"]
request["execute_processes"] = ["analyze"]
# 修正工具展示名称
if "checktool" in request["task_params"]:
request["task_params"]["checktool"]["display_name"] = "LineCount"
request["task_params"]["checktool"]["show_display_name"] = True
# 完善task request字段
RequestModify.modify_local_task_request(request, task_name_id_maps, job_id,
scm_auth_info.ssh_file,
token, server_url, source_dir, scm_info,
scm_auth_info, create_from)
# 执行单个任务扫描
logger.info("启动 linecount 工具统计代码行...")
task = SingleTaskRuner(request, env=origin_os_env).run()
with open(task.response_file, 'r') as fp:
task_result = json.load(fp)
# 代码行和scm数据保存在结果字典的"result"下的"result"字段中
response_data = task_result["result"]["result"]
code_line_count = response_data["code_line"]
scm_info.scm_time = response_data["scm_info"]["scm_time"]
if code_line_count:
logger.info(f"本次分析代码行数: {code_line_count.get('filtered_total_line_num')}")
logger.info(f"全量代码行数: {code_line_count.get('total_line_num')}")
return code_line_count