-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #577 from bensonhome/main
工具拉取支持htttp zip包地址
- Loading branch information
Showing
14 changed files
with
128 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# -*- encoding: utf-8 -*- | ||
# Copyright (c) 2022 THL A29 Limited | ||
# | ||
# This source code file is made available under MIT License | ||
# See LICENSE for details | ||
# ============================================================================== | ||
|
||
""" | ||
通过http方式拉取工具 | ||
""" | ||
|
||
import os | ||
|
||
from util.logutil import LogPrinter | ||
from util.api.fileserver import RetryFileServer | ||
from util.exceptions import FileServerError | ||
from util.ziplib import ZipMgr | ||
|
||
|
||
class HttpToolLoader(object): | ||
"""通过http方式拉取工具,如果目录已存在,不拉取""" | ||
@staticmethod | ||
def download_tool(tool_url, dest_dir): | ||
if os.path.exists(dest_dir): | ||
# 工具目录存在时,直接复用,不重新拉取(如需更新,先删除工具目录) | ||
LogPrinter.debug(f"tool dir({os.path.basename(dest_dir)}) from zip can be reused.") | ||
return | ||
|
||
tool_root_dir = os.path.dirname(dest_dir) | ||
if not os.path.exists(tool_root_dir): # 如果上层目录不存在,先创建 | ||
os.makedirs(tool_root_dir) | ||
zip_file_name = tool_url.split('/')[-1] | ||
dest_zip_file_path = os.path.join(tool_root_dir, zip_file_name) | ||
|
||
file_server = RetryFileServer(retry_times=2).get_server(server_url=tool_url) | ||
file_server.download_big_file("", dest_zip_file_path) | ||
|
||
if os.path.exists(dest_zip_file_path): | ||
LogPrinter.debug(f"download {tool_url} to {dest_zip_file_path}") | ||
ZipMgr.depress(dest_zip_file_path, tool_root_dir) | ||
LogPrinter.debug(f"unzip {dest_zip_file_path} to {dest_dir}") | ||
else: | ||
raise FileServerError(f"download {tool_url} failed!") | ||
|
||
|
||
if __name__ == '__main__': | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters