统计代码行线程
| 25 | |
| 26 | |
| 27 | class CountLineThread(threading.Thread): |
| 28 | """ |
| 29 | 统计代码行线程 |
| 30 | """ |
| 31 | def __init__(self, event, task_params, work_dir, result_path): |
| 32 | """ |
| 33 | 构造函数 |
| 34 | :param event: |
| 35 | :param task_params: |
| 36 | :param result_path: |
| 37 | :return: |
| 38 | """ |
| 39 | threading.Thread.__init__(self) |
| 40 | self._thread_event = event |
| 41 | self._task_params = task_params |
| 42 | self._work_dir = work_dir |
| 43 | self._result_path = result_path |
| 44 | |
| 45 | def run(self): |
| 46 | # self._thread_event.set() |
| 47 | try: |
| 48 | LogPrinter.info("Start to count code lines...") |
| 49 | # 删除旧结果文件 |
| 50 | if os.path.exists(self._result_path): |
| 51 | PathMgr().rmpath(self._result_path) |
| 52 | |
| 53 | # 修改任务参数,确保代码量统计到准确的diff文件范围 |
| 54 | InitParams.prepare_params_about_path_filters(self._task_params) |
| 55 | |
| 56 | # 加载codecount工具环境变量,即加载cloc命令需要的环境变量(cloc是通用工具,已经在之前拉取过,不需要重复拉取) |
| 57 | ToolLoader(tool_names=["codecount"], include_common=True).set_tool_env() |
| 58 | |
| 59 | code_line_data = CodeLineCount(self._task_params, self._work_dir).run() |
| 60 | |
| 61 | with open(self._result_path, "w") as wf: |
| 62 | json.dump(code_line_data, wf, indent=2) |
| 63 | except Exception as err: |
| 64 | LogPrinter.error("linecount raise error: %s" % err) |
| 65 | raise |
| 66 | finally: |
| 67 | self._thread_event.clear() |
| 68 | |
| 69 | |
| 70 | class LocalCountLine(object): |