From 6037837731df161f40323cd00044168d4f8e712b Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Tue, 6 Sep 2022 01:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E6=8B=B7?= =?UTF-8?q?=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/admin.html | 7 ++++++- utils/update.py | 22 +++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/templates/admin.html b/templates/admin.html index bc4b8ad..dc900db 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -105,7 +105,12 @@ $.get("/admin/update_ver",function(data,status){ console.log(data); alert(data.msg||'未知数据,具体到数据控制台查看'); - return false + if(data.code !== 200){ + console.log('升级失败了...'); + return false + }else{ + location.reload() + } }); } }else{ diff --git a/utils/update.py b/utils/update.py index b4af08f..9932933 100644 --- a/utils/update.py +++ b/utils/update.py @@ -7,6 +7,7 @@ import requests import os import zipfile +import shutil # https://blog.csdn.net/weixin_33130113/article/details/112336581 def getLocalVer(): base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 @@ -49,6 +50,19 @@ def del_file(filepath): if os.path.isfile(file_path): os.remove(file_path) +def copy_to_update(): + base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 + tmp_path = os.path.join(base_path, f'tmp') + dr_path = os.path.join(tmp_path, f'dr_py-master') + if not os.path.exists(dr_path): + print(f'升级失败,找不到目录{dr_path}') + return False + from_path = os.path.join(dr_path, f'js') + to_path = os.path.join(base_path, f'js') + print(f'开始拷贝文件{from_path}=>{to_path}') + shutil.copytree(from_path, to_path) + return True + def download_new_version(): base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 tmp_path = os.path.join(base_path, f'tmp') @@ -76,8 +90,10 @@ def download_new_version(): for file in f.namelist(): f.extract(file, tmp_path) # 解压位置 f.close() - print('解压完毕') - msg = '下载成功' + print('解压完毕,开始升级') + ret = copy_to_update() + print(f'升级完毕,结果为:{ret}') + msg = '升级成功' except Exception as e: - msg = f'下载失败:{e}' + msg = f'升级失败:{e}' return msg \ No newline at end of file -- GitLab