From 9e28298250403db52950c07ac22fdd1f9e2b25e7 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Mon, 6 Mar 2023 11:18:31 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=AE=8C=E5=96=84=E6=9C=AA=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=83=85=E5=86=B5=E4=B8=8B=E7=9A=84=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 3 ++- pkg/utils/updater.py | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 3f24ac68..46e1d276 100644 --- a/main.py +++ b/main.py @@ -343,8 +343,9 @@ if __name__ == '__main__': sys.exit(0) elif len(sys.argv) > 1 and sys.argv[1] == 'update': + print("正在进行程序更新...") import pkg.utils.updater as updater - updater.update_all() + updater.update_all(cli=True) sys.exit(0) # import pkg.utils.configmgr diff --git a/pkg/utils/updater.py b/pkg/utils/updater.py index b3653811..d2d89517 100644 --- a/pkg/utils/updater.py +++ b/pkg/utils/updater.py @@ -54,7 +54,7 @@ def get_current_tag() -> str: return current_tag -def update_all(cli: bool=False) -> bool: +def update_all(cli: bool = False) -> bool: """检查更新并下载源码""" current_tag = get_current_tag() @@ -69,12 +69,19 @@ def update_all(cli: bool=False) -> bool: if latest_rls == {}: latest_rls = rls - logging.info("更新日志: {}".format(rls_notes)) + if not cli: + logging.info("更新日志: {}".format(rls_notes)) + else: + print("更新日志: {}".format(rls_notes)) + if latest_rls == {}: # 没有新版本 return False # 下载最新版本的zip到temp目录 - logging.info("开始下载最新版本: {}".format(latest_rls['zipball_url'])) + if not cli: + logging.info("开始下载最新版本: {}".format(latest_rls['zipball_url'])) + else: + print("开始下载最新版本: {}".format(latest_rls['zipball_url'])) zip_url = latest_rls['zipball_url'] zip_resp = requests.get(url=zip_url) zip_data = zip_resp.content @@ -87,7 +94,10 @@ def update_all(cli: bool=False) -> bool: with open("temp/updater/{}.zip".format(latest_rls['tag_name']), "wb") as f: f.write(zip_data) - logging.info("下载最新版本完成: {}".format("temp/updater/{}.zip".format(latest_rls['tag_name']))) + if not cli: + logging.info("下载最新版本完成: {}".format("temp/updater/{}.zip".format(latest_rls['tag_name']))) + else: + print("下载最新版本完成: {}".format("temp/updater/{}.zip".format(latest_rls['tag_name']))) # 解压zip到temp/updater// import zipfile