工具拉取管理类
| 171 | |
| 172 | |
| 173 | class ToolLoader(object): |
| 174 | """工具拉取管理类""" |
| 175 | |
| 176 | def __init__(self, tool_names=None, os_type=None, task_list=None, custom_tools=None, config_all_tools=False, include_common=True): |
| 177 | """ |
| 178 | 构造函数 |
| 179 | :param tool_names: <list> 工具名列表,可以指定单个或多个工具;默认为空,表示全量工具 |
| 180 | :param os_type: <str> 操作系统,可以指定拉取某个OS(忽略当前机器环境所处OS)的工具 |
| 181 | :param task_list: <list> 任务参数的列表,可以包含单个或多个工具任务 |
| 182 | :return: |
| 183 | """ |
| 184 | # 读取工具配置信息 |
| 185 | self.__tool_config = ConfigLoader(os_type=os_type).read_tool_config(tool_names=tool_names, |
| 186 | task_list=task_list, |
| 187 | custom_tools=custom_tools, |
| 188 | config_all_tools=config_all_tools, |
| 189 | include_common=include_common) |
| 190 | |
| 191 | def git_load_tools(self, print_enable): |
| 192 | """ |
| 193 | 按需拉取|更新内置工具库(自定义工具不通过该方法拉取) |
| 194 | :param print_enable: 是否打印拉取过程 |
| 195 | :param tool_names: |
| 196 | :return: |
| 197 | """ |
| 198 | # 拉取工具 |
| 199 | tool_url_info = {} |
| 200 | for tool_name, tool_info in self.__tool_config.items(): |
| 201 | if tool_info["tool_url"]: |
| 202 | tool_url = tool_info["tool_url"] |
| 203 | if isinstance(tool_url, list): |
| 204 | for url in tool_url: |
| 205 | tool_url_info[url] = tool_info |
| 206 | else: |
| 207 | tool_url_info[tool_url] = tool_info |
| 208 | # LogPrinter.info(f">>>>>type:{type(tool_url_info)}\n tool_url_info: {tool_url_info}") |
| 209 | # import json |
| 210 | # LogPrinter.info(">>> 工具配置: %s" % json.dumps(self.__tool_config, indent=1)) |
| 211 | |
| 212 | # LogPrinter.info("开始更新工具...") |
| 213 | load_tool_list = [] |
| 214 | tool_dirname_list = [] |
| 215 | for git_url, tool_info in tool_url_info.items(): |
| 216 | tool_dirname = BaseScmUrlMgr.get_last_dir_name_from_url(git_url) |
| 217 | # 工具目录名重复,说明是同一工具,去重,避免重复拉取造成线程冲突 |
| 218 | if tool_dirname in tool_dirname_list: |
| 219 | continue |
| 220 | else: |
| 221 | tool_dirname_list.append(tool_dirname) |
| 222 | tool_dirpath = os.path.join(settings.TOOL_BASE_DIR, tool_dirname) |
| 223 | |
| 224 | load_type, dirpath_copy_from = ToolCommonLoader.load_tool_type(tool_dirpath, tool_dirname, git_url) |
| 225 | |
| 226 | load_tool_list.append({ |
| 227 | "load_type": load_type, |
| 228 | "git_url": git_url, |
| 229 | "tool_dirname": tool_dirname, |
| 230 | "tool_dirpath": tool_dirpath, |
no outgoing calls
no test coverage detected