mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
🐛 修复更新
会消除插件的问题
This commit is contained in:
parent
190a9b5ae1
commit
7d08988347
@ -4,7 +4,7 @@ from nonebot import get_driver
|
||||
from .logger import logger
|
||||
from .scheduler import scheduler
|
||||
|
||||
__version__ = '3.0.1'
|
||||
__version__ = '3.0.2'
|
||||
|
||||
DRIVER = get_driver()
|
||||
try:
|
||||
|
@ -39,28 +39,31 @@ async def check_update():
|
||||
|
||||
@run_sync
|
||||
def update():
|
||||
pyproject_file = Path().parent / 'pyproject.toml'
|
||||
pyproject_raw_content = pyproject_file.read_text(encoding='utf-8')
|
||||
if raw_plugins_load := re.search(r'^plugins = \[.*]$', pyproject_raw_content, flags=re.M):
|
||||
pyproject_new_content = pyproject_raw_content.replace(raw_plugins_load.group(), 'plugins = []')
|
||||
else:
|
||||
pyproject_new_content = pyproject_raw_content
|
||||
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
|
||||
try:
|
||||
repo = git.Repo(Path().absolute())
|
||||
except InvalidGitRepositoryError:
|
||||
return '没有发现git仓库,无法通过git更新,请手动下载最新版本的文件进行替换。'
|
||||
origin = repo.remotes.origin
|
||||
pyproject_file = Path().parent / 'pyproject.toml'
|
||||
pyproject_raw_content = pyproject_file.read_text(encoding='utf-8')
|
||||
if raw_plugins_load := re.search(r'^plugins = \[.+]$', pyproject_raw_content, flags=re.M):
|
||||
pyproject_new_content = pyproject_raw_content.replace(raw_plugins_load.group(), 'plugins = []')
|
||||
else:
|
||||
pyproject_new_content = pyproject_raw_content
|
||||
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
|
||||
try:
|
||||
origin.pull()
|
||||
msg = f'更新完成,版本:{__version__}\n最新更新日志为:\n{repo.head.commit.message.replace(":bug:", "🐛").replace(":sparkles:", "✨").replace(":memo:", "📝")}\n可使用命令[@bot 重启]重启{NICKNAME}'
|
||||
except GitCommandError as e:
|
||||
if 'timeout' in e or 'unable to access' in e:
|
||||
return '更新失败,连接git仓库超时,请重试或修改源为代理源后再重试。'
|
||||
msg = '更新失败,连接git仓库超时,请重试或修改源为代理源后再重试。'
|
||||
elif ' Your local changes to the following files would be overwritten by merge' in e:
|
||||
return ('error: Your local changes to the following files would be overwritten by merge\n'
|
||||
'更新失败,本地修改过文件导致冲突,可在命令行运行git pull查看冲突的文件是哪些,请解决冲突后再更新。')
|
||||
return f'更新失败,错误信息:{e},请尝试手动进行更新'
|
||||
pyproject_new_content = pyproject_file.read_text(encoding='utf-8')
|
||||
pyproject_new_content = pyproject_new_content.replace('plugins = []', raw_plugins_load.group())
|
||||
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
|
||||
return f'更新完成,版本:{__version__}\n最新更新日志为:\n{repo.head.commit.message.replace(":bug:", "🐛").replace(":sparkles:", "✨").replace(":memo:", "📝")}\n可使用命令[@bot 重启]重启{NICKNAME}'
|
||||
msg = ('error: Your local changes to the following files would be overwritten by merge\n'
|
||||
'更新失败,本地修改过文件导致冲突,可在命令行运行git pull查看冲突的文件是哪些,请解决冲突后再更新。')
|
||||
else:
|
||||
msg = f'更新失败,错误信息:{e},请尝试手动进行更新'
|
||||
if raw_plugins_load:
|
||||
pyproject_new_content = pyproject_file.read_text(encoding='utf-8')
|
||||
pyproject_new_content = pyproject_new_content.replace('plugins = []', raw_plugins_load.group())
|
||||
pyproject_file.write_text(pyproject_new_content, encoding='utf-8')
|
||||
return msg
|
||||
|
Loading…
x
Reference in New Issue
Block a user