Skip to content

Commit e4793f0

Browse files
committed
增加下载进度显示,优化用户体验
1 parent 2d33b8c commit e4793f0

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Docker Image Puller 是一个方便的工具,用于从 Docker 仓库拉取镜
77
## 特点
88

99
- **无需安装 Docker 或 Python 环境**:直接使用单文件 EXE 或 Python 脚本,开箱即用。
10+
- **无依赖 EXE 执行**:编译为独立 EXE 文件,无需安装 Python 环境,无需安装 Docker 环境,直接在 Releases 下载就能直接使用。
1011
- **国内镜像源加速**:通过配置国内镜像源,大幅提高镜像下载速度,解决国内无法直接下载的问题。
1112
- **多架构支持**:支持多种架构(如 `amd64``arm64`),满足不同环境需求,尤其是 arm64 内网服务器。
1213
- **兼容最新 Docker Hub API**:确保与 Docker Hub 的最新接口兼容,获取最新的镜像信息。
1314
- **单文件 Python 脚本**:便于携带和使用,无需复杂安装。
14-
- **无依赖 EXE 执行**:编译为独立 EXE 文件,无需安装 Python 环境,无法安装 Docker 环境,直接在 Releases 下载就能直接使用。
1515
- **用户友好**:提供交互式输入,简化操作流程。
1616
- **优化性能**:提高下载速度和可靠性。
1717

clear.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@REM 删除多余文件
2-
@REM rmdir dist /s /q
2+
rmdir dist /s /q
33
rmdir build /s /q
44
del DockerPull.exe.spec
55
del Pipfile*

dev.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pipenv shell
1717

1818
``` bat
1919
@REM 安装依赖,在虚拟环境中
20-
pip install pyinstaller requests urllib3 -i https://pypi.tuna.tsinghua.edu.cn/simple/
20+
pip install pyinstaller requests urllib3 tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple/
2121
@REM 打包
2222
pyinstaller -F -n DockerPull.exe -i favicon.ico docker_image_puller.py
2323
@REM 卸载依赖

docker_image_puller.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import requests
88
from requests.adapters import HTTPAdapter
99
from urllib3.util.retry import Retry
10+
from tqdm import tqdm
1011
import tarfile
1112
import urllib3
1213
urllib3.disable_warnings()
@@ -130,13 +131,20 @@ def download_layers(session, registry, repository, layers, auth_head, imgdir, re
130131
try:
131132
bresp = session.get(f'https://{registry}/v2/{repository}/blobs/{ublob}', headers=auth_head, stream=True, verify=False, timeout=30)
132133
bresp.raise_for_status()
134+
135+
# 使用 tqdm 显示下载进度
136+
total_size = int(bresp.headers.get('content-length', 0))
137+
with tqdm(total=total_size, unit='B', unit_scale=True, desc=f'Downloading {ublob[:12]}') as pbar:
138+
with open(f'{layerdir}/layer_gzip.tar', 'wb') as file:
139+
for chunk in bresp.iter_content(chunk_size=1024):
140+
if chunk:
141+
file.write(chunk)
142+
pbar.update(len(chunk))
143+
133144
except requests.exceptions.RequestException as e:
134145
print(f'下载层错误:{e}')
135146
exit(1)
136147

137-
with open(f'{layerdir}/layer_gzip.tar', 'wb') as file:
138-
shutil.copyfileobj(bresp.raw, file)
139-
140148
with open(f'{layerdir}/layer.tar', 'wb') as file:
141149
with gzip.open(f'{layerdir}/layer_gzip.tar', 'rb') as gz:
142150
shutil.copyfileobj(gz, file)
@@ -229,6 +237,7 @@ def main():
229237
if not os.path.exists(imgdir):
230238
os.makedirs(imgdir)
231239

240+
print('开始下载层...')
232241
download_layers(session, registry, repository, layers, auth_head, imgdir, resp_json, imgparts, img, tag)
233242

234243
create_image_tar(imgdir, repo, img)

0 commit comments

Comments
 (0)