From f3787341e20d94ffd00807e27c3a7d9ab9a6fcb6 Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Tue, 6 Sep 2022 21:04:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpython3.8=E4=BB=A5=E4=B8=8B?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8D=87=E7=BA=A7=E5=BC=82=E5=B8=B8=E9=97=AE?= =?UTF-8?q?=E9=A2=98(=E7=94=B1=E4=BA=8Edirs=5Fexist=5Fok=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E6=98=AF3.8=E4=BB=A5=E5=90=8E=E6=89=8D=E6=9C=89=E7=9A=84)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/update.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/utils/update.py b/utils/update.py index 964386e..bae1552 100644 --- a/utils/update.py +++ b/utils/update.py @@ -5,7 +5,7 @@ # Date : 2022/9/6 import re from time import time as getTime - +import sys import requests import os import zipfile @@ -60,10 +60,31 @@ def del_file(filepath): if os.path.isfile(file_path): os.remove(file_path) +def copytree(src, dst): + dirs = os.listdir(src) # 获取目录下的所有文件包括文件夹 + # print(dirs) + for dir in dirs: # 遍历文件或文件夹 + from_dir = os.path.join(src, dir) # 将要复制的文件夹或文件路径 + to_dir = os.path.join(dst, dir) # 将要复制到的文件夹或文件路径 + if os.path.isdir(from_dir): # 判断是否为文件夹 + if not os.path.exists(to_dir): # 判断目标文件夹是否存在,不存在则创建 + os.mkdir(to_dir) + copytree(from_dir, to_dir) # 迭代 遍历子文件夹并复制文件 + elif os.path.isfile(from_dir): # 如果为文件,则直接复制文件 + shutil.copy(from_dir, to_dir) # 复制文件 + + def force_copy_files(from_path,to_path): # print(f'开始拷贝文件{from_path}=>{to_path}') logger.info(f'开始拷贝文件{from_path}=>{to_path}') - shutil.copytree(from_path, to_path, dirs_exist_ok=True) + try: + if sys.version_info < (3, 8): + copytree(from_path, to_path) + else: + shutil.copytree(from_path, to_path, dirs_exist_ok=True) + + except Exception as e: + logger.info(f'拷贝文件{from_path}=>{to_path}发生错误:{e}') def copy_to_update(): base_path = os.path.dirname(os.path.abspath(os.path.dirname(__file__))) # 上级目录 -- GitLab