Sfoglia il codice sorgente

增加下载进度条

kinve 2 anni fa
parent
commit
9d1391b57d
4 ha cambiato i file con 12 aggiunte e 3 eliminazioni
  1. 11 3
      GitAutoupdater.py
  2. BIN
      dist/GitAutoupdater.exe
  3. BIN
      upx.exe
  4. 1 0
      生成exe.bat

+ 11 - 3
GitAutoupdater.py

@@ -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()

BIN
dist/GitAutoupdater.exe


BIN
upx.exe


+ 1 - 0
生成exe.bat

@@ -0,0 +1 @@
+pyinstaller -F .\GitAutoupdater.py