提交 63352f7b 编写于 作者: H hjdhnx

增加升级时不覆盖txt目录的三个规定配置文件

上级 d4e5ef01
...@@ -40,7 +40,8 @@ ...@@ -40,7 +40,8 @@
$.get("/admin/update_ver",function(data,status){ $.get("/admin/update_ver",function(data,status){
console.log(data); console.log(data);
if(data.code === 200){ if(data.code === 200){
alert(data.msg+'\n除主程序app.py需要自行检测替换升级外,其他关键文件全部更新完毕'); // alert(data.msg+'\n除主程序app.py需要自行检测替换升级外,其他关键文件全部更新完毕');
alert(data.msg);
location.reload(); location.reload();
}else{ }else{
alert(data.msg||'未知数据,具体到数据控制台查看'); alert(data.msg||'未知数据,具体到数据控制台查看');
...@@ -153,7 +154,8 @@ ...@@ -153,7 +154,8 @@
$.get("/admin/force_update",function(data,status){ $.get("/admin/force_update",function(data,status){
console.log(data); console.log(data);
if(data.code === 200){ if(data.code === 200){
alert(data.msg+'\n除主程序app.py需要自行检测替换升级外,其他关键文件全部更新完毕'); // alert(data.msg+'\n除主程序app.py需要自行检测替换升级外,其他关键文件全部更新完毕');
alert(data.msg);
location.reload(); location.reload();
}else{ }else{
alert(data.msg||'未知数据,具体到数据控制台查看'); alert(data.msg||'未知数据,具体到数据控制台查看');
......
...@@ -62,7 +62,9 @@ def del_file(filepath): ...@@ -62,7 +62,9 @@ def del_file(filepath):
if os.path.isfile(file_path): if os.path.isfile(file_path):
os.remove(file_path) os.remove(file_path)
def copytree(src, dst): def copytree(src, dst, ignore=None):
if ignore is None:
ignore = []
dirs = os.listdir(src) # 获取目录下的所有文件包括文件夹 dirs = os.listdir(src) # 获取目录下的所有文件包括文件夹
# print(dirs) # print(dirs)
for dir in dirs: # 遍历文件或文件夹 for dir in dirs: # 遍历文件或文件夹
...@@ -71,19 +73,30 @@ def copytree(src, dst): ...@@ -71,19 +73,30 @@ def copytree(src, dst):
if os.path.isdir(from_dir): # 判断是否为文件夹 if os.path.isdir(from_dir): # 判断是否为文件夹
if not os.path.exists(to_dir): # 判断目标文件夹是否存在,不存在则创建 if not os.path.exists(to_dir): # 判断目标文件夹是否存在,不存在则创建
os.mkdir(to_dir) os.mkdir(to_dir)
copytree(from_dir, to_dir) # 迭代 遍历子文件夹并复制文件 copytree(from_dir, to_dir,ignore) # 迭代 遍历子文件夹并复制文件
elif os.path.isfile(from_dir): # 如果为文件,则直接复制文件 elif os.path.isfile(from_dir): # 如果为文件,则直接复制文件
shutil.copy(from_dir, to_dir) # 复制文件 if ignore:
regxp = '|'.join(ignore).replace('\\','/') # 组装正则
to_dir_str = str(to_dir).replace('\\','/')
if not re.search(rf'{regxp}', to_dir_str, re.M):
shutil.copy(from_dir, to_dir) # 复制文件
else:
shutil.copy(from_dir, to_dir) # 复制文件
def force_copy_files(from_path,to_path): def force_copy_files(from_path, to_path, exclude_files=None):
# print(f'开始拷贝文件{from_path}=>{to_path}') # print(f'开始拷贝文件{from_path}=>{to_path}')
if exclude_files is None:
exclude_files = []
logger.info(f'开始拷贝文件{from_path}=>{to_path}') logger.info(f'开始拷贝文件{from_path}=>{to_path}')
try: try:
if sys.version_info < (3, 8): if sys.version_info < (3, 8):
copytree(from_path, to_path) copytree(from_path, to_path,exclude_files)
else: else:
shutil.copytree(from_path, to_path, dirs_exist_ok=True) if len(exclude_files) > 0:
shutil.copytree(from_path, to_path, dirs_exist_ok=True,ignore=shutil.ignore_patterns(*exclude_files))
else:
shutil.copytree(from_path, to_path, dirs_exist_ok=True)
except Exception as e: except Exception as e:
logger.info(f'拷贝文件{from_path}=>{to_path}发生错误:{e}') logger.info(f'拷贝文件{from_path}=>{to_path}发生错误:{e}')
...@@ -98,8 +111,9 @@ def copy_to_update(): ...@@ -98,8 +111,9 @@ def copy_to_update():
return False return False
# 千万不能覆盖super,base # 千万不能覆盖super,base
paths = ['js','models','controllers','libs','static','templates','utils','txt'] paths = ['js','models','controllers','libs','static','templates','utils','txt']
exclude_files = ['txt/pycms0.json','txt/pycms1.json','txt/pycms2.json']
for path in paths: for path in paths:
force_copy_files(os.path.join(dr_path, path),os.path.join(base_path, path)) force_copy_files(os.path.join(dr_path, path),os.path.join(base_path, path),exclude_files)
try: try:
shutil.copy(os.path.join(dr_path, 'app.py'), os.path.join(base_path, 'app.py')) # 复制文件 shutil.copy(os.path.join(dr_path, 'app.py'), os.path.join(base_path, 'app.py')) # 复制文件
except Exception as e: except Exception as e:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册