MCPcopy Index your code
hub / github.com/Tencent/CodeAnalysis / download_tool

Method download_tool

client/node/toolloader/httploadtool.py:24–46  ·  view source on GitHub ↗
(tool_url, dest_dir)

Source from the content-addressed store, hash-verified

22 """通过http方式拉取工具,如果目录已存在,不拉取"""
23 @staticmethod
24 def download_tool(tool_url, dest_dir):
25 if os.path.exists(dest_dir):
26 # 工具目录存在时,直接复用,不重新拉取(如需更新,先删除工具目录)
27 LogPrinter.debug(f"tool dir({os.path.basename(dest_dir)}) from zip can be reused.")
28 return
29
30 tool_root_dir = os.path.dirname(dest_dir)
31 if not os.path.exists(tool_root_dir): # 如果上层目录不存在,先创建
32 os.makedirs(tool_root_dir)
33 zip_file_name = tool_url.split('/')[-1]
34 dest_zip_file_path = os.path.join(tool_root_dir, zip_file_name)
35
36 file_server = RetryFileServer(retry_times=2).get_server(server_url=tool_url)
37 file_server.download_big_file("", dest_zip_file_path)
38
39 if os.path.exists(dest_zip_file_path):
40 LogPrinter.debug(f"download {tool_url} to {dest_zip_file_path}")
41 # 使用7z解压
42 Zip().decompress_by_7z(dest_zip_file_path, tool_root_dir)
43 LogPrinter.debug(f"unzip {dest_zip_file_path} to {dest_dir}")
44 PathMgr().safe_rmpath(dest_zip_file_path)
45 else:
46 raise FileServerError(f"download {tool_url} failed!")
47
48
49if __name__ == '__main__':

Callers 1

load_toolMethod · 0.80

Calls 7

RetryFileServerClass · 0.90
ZipClass · 0.90
FileServerErrorClass · 0.90
debugMethod · 0.80
get_serverMethod · 0.80
download_big_fileMethod · 0.80
decompress_by_7zMethod · 0.80

Tested by

no test coverage detected