mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
Update data_source.py
This commit is contained in:
parent
65d8fae9ca
commit
66fa194c7f
@ -128,7 +128,7 @@ def _file_handle(latest_version: str) -> str:
|
|||||||
shutil.rmtree(backup_dir)
|
shutil.rmtree(backup_dir)
|
||||||
tf = None
|
tf = None
|
||||||
error = ''
|
error = ''
|
||||||
try:
|
# try:
|
||||||
backup_dir.mkdir(exist_ok=True, parents=True)
|
backup_dir.mkdir(exist_ok=True, parents=True)
|
||||||
logger.info("开始解压真寻文件压缩包....")
|
logger.info("开始解压真寻文件压缩包....")
|
||||||
tf = tarfile.open(zhenxun_latest_tar_gz)
|
tf = tarfile.open(zhenxun_latest_tar_gz)
|
||||||
@ -141,8 +141,19 @@ def _file_handle(latest_version: str) -> str:
|
|||||||
add_file = update_info["add_file"]
|
add_file = update_info["add_file"]
|
||||||
delete_file = update_info["delete_file"]
|
delete_file = update_info["delete_file"]
|
||||||
config_file = Path() / "configs" / "config.py"
|
config_file = Path() / "configs" / "config.py"
|
||||||
config_path_file = Path() / "configs" / "config_path.py"
|
config_path_file = Path() / "configs" / "path_config.py"
|
||||||
|
for file in [config_file.name]:
|
||||||
|
tmp = ""
|
||||||
|
new_file = Path(zhenxun_latest_file) / "configs" / file
|
||||||
|
old_file = Path() / "configs" / file
|
||||||
|
new_lines = open(new_file, "r", encoding="utf8").readlines()
|
||||||
|
old_lines = open(old_file, "r", encoding="utf8").readlines()
|
||||||
|
for nl in new_lines:
|
||||||
|
tmp += check_old_lines(old_lines, nl)
|
||||||
|
with open(old_file, "w", encoding="utf8") as f:
|
||||||
|
f.write(tmp)
|
||||||
for file in delete_file + update_file:
|
for file in delete_file + update_file:
|
||||||
|
if file != "configs":
|
||||||
file = Path() / file
|
file = Path() / file
|
||||||
backup_file = Path(backup_dir) / file
|
backup_file = Path(backup_dir) / file
|
||||||
if file.exists():
|
if file.exists():
|
||||||
@ -160,20 +171,12 @@ def _file_handle(latest_version: str) -> str:
|
|||||||
for file in add_file + update_file:
|
for file in add_file + update_file:
|
||||||
new_file = Path(zhenxun_latest_file) / file
|
new_file = Path(zhenxun_latest_file) / file
|
||||||
old_file = Path() / file
|
old_file = Path() / file
|
||||||
if old_file not in [config_file, config_path_file]:
|
if old_file not in [config_file, config_path_file] and file != "configs":
|
||||||
if not old_file.exists() and new_file.exists():
|
if not old_file.exists() and new_file.exists():
|
||||||
os.rename(new_file.absolute(), old_file.absolute())
|
os.rename(new_file.absolute(), old_file.absolute())
|
||||||
logger.info(f"已更新文件:{file}")
|
logger.info(f"已更新文件:{file}")
|
||||||
else:
|
# except Exception as e:
|
||||||
tmp = ""
|
# error = f'{type(e)}:{e}'
|
||||||
new_lines = open(new_file, "r", encoding="utf8").readlines()
|
|
||||||
old_lines = open(old_file, "r", encoding="utf8").readlines()
|
|
||||||
for nl in new_lines:
|
|
||||||
tmp += check_old_lines(old_lines, nl)
|
|
||||||
with open(file, "w", encoding="utf8") as f:
|
|
||||||
f.write(tmp)
|
|
||||||
except Exception as e:
|
|
||||||
error = f'{type(e)}:{e}'
|
|
||||||
if tf:
|
if tf:
|
||||||
tf.close()
|
tf.close()
|
||||||
if temp_dir.exists():
|
if temp_dir.exists():
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user