|
|
@@ -6,6 +6,14 @@ from urllib.request import urlretrieve
|
|
|
import os
|
|
|
import argparse
|
|
|
|
|
|
+def reporthook(count, block_size, total_size):
|
|
|
+ """
|
|
|
+ 函数名可以自定义,参数 count 表示当前已经下载的数据块数目,
|
|
|
+ block_size 表示每个数据块的大小,total_size 表示下载目标的总大小
|
|
|
+ """
|
|
|
+ percent = int(count * block_size * 100 / total_size)
|
|
|
+ print('\r', f"正在下载:{count * block_size} / {total_size} bytes ({percent}%)", end='', flush=True)
|
|
|
+
|
|
|
def http_down(project, down_list=[], proxy=""):
|
|
|
git_api = "https://api.github.com/repos/{}/releases/latest".format(project)
|
|
|
git_releases="https://github.com/{}/releases/download/".format(project)
|
|
|
@@ -21,9 +29,9 @@ def http_down(project, down_list=[], proxy=""):
|
|
|
if not os.path.exists(latest_version):
|
|
|
os.makedirs(latest_version)
|
|
|
for i in down_list:
|
|
|
- print('down {}...'.format(i))
|
|
|
- urlretrieve(git_down_url+i, latest_version+"/"+i)
|
|
|
- print("下载完成")
|
|
|
+ print('下载 {}...'.format(i))
|
|
|
+ urlretrieve(git_down_url+i, latest_version+"/"+i, reporthook)
|
|
|
+ print("\n下载完成")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
parser = argparse.ArgumentParser()
|