更新升级脚本

This commit is contained in:
晚风拂柳颜 2023-07-07 15:46:06 +08:00
parent 7c6ab89911
commit 96c22b7298
2 changed files with 8 additions and 2 deletions

View File

@ -1 +1 @@
3.9.46beta8 3.9.46beta9

View File

@ -106,6 +106,11 @@ def del_file(filepath):
file_path = os.path.join(filepath, f) file_path = os.path.join(filepath, f)
if os.path.isfile(file_path): if os.path.isfile(file_path):
os.remove(file_path) os.remove(file_path)
else:
try:
shutil.rmtree(file_path)
except Exception as e:
logger.info(f'删除{file_path}发生错误:{e}')
def copytree(src, dst, ignore=None): def copytree(src, dst, ignore=None):
if ignore is None: if ignore is None:
@ -194,7 +199,6 @@ def download_new_version(update_proxy='https://ghproxy.liuzhicong.com/'):
# for tp in tmp_files: # for tp in tmp_files:
# print(f'清除缓存文件:{tp}') # print(f'清除缓存文件:{tp}')
# os.remove(os.path.join(tmp_path, tp)) # os.remove(os.path.join(tmp_path, tp))
del_file(tmp_path)
msg = '' msg = ''
try: try:
# print(f'开始下载:{url}') # print(f'开始下载:{url}')
@ -202,6 +206,8 @@ def download_new_version(update_proxy='https://ghproxy.liuzhicong.com/'):
r = requests.get(url,headers=headers,timeout=(20,20),verify=False) r = requests.get(url,headers=headers,timeout=(20,20),verify=False)
rb = r.content rb = r.content
download_path = os.path.join(tmp_path, 'dr_py.zip') download_path = os.path.join(tmp_path, 'dr_py.zip')
# 保存文件前清空目录
del_file(tmp_path)
with open(download_path,mode='wb+') as f: with open(download_path,mode='wb+') as f:
f.write(rb) f.write(rb)
# print(f'开始解压文件:{download_path}') # print(f'开始解压文件:{download_path}')