mirror of
https://github.com/xuthus83/LittlePaimon.git
synced 2024-12-16 13:40:53 +08:00
✨ 优化更新
提示
This commit is contained in:
parent
1ebd44296b
commit
905245be79
@ -1,4 +1,5 @@
|
|||||||
import datetime
|
import datetime
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import git
|
import git
|
||||||
@ -28,7 +29,9 @@ async def check_update():
|
|||||||
return f'当前已是最新版本:{__version__}'
|
return f'当前已是最新版本:{__version__}'
|
||||||
result = '检查到更新,日志如下:\n'
|
result = '检查到更新,日志如下:\n'
|
||||||
for i, commit in enumerate(remote_commit, start=1):
|
for i, commit in enumerate(remote_commit, start=1):
|
||||||
time_str = (datetime.datetime.strptime(commit['commit']['committer']['date'], '%Y-%m-%dT%H:%M:%SZ') + datetime.timedelta(hours=8)).strftime('%Y-%m-%d %H:%M:%S')
|
time_str = (datetime.datetime.strptime(commit['commit']['committer']['date'],
|
||||||
|
'%Y-%m-%dT%H:%M:%SZ') + datetime.timedelta(hours=8)).strftime(
|
||||||
|
'%Y-%m-%d %H:%M:%S')
|
||||||
result += f'{i}.{time_str}\n' + commit['commit']['message'].replace(':bug:', '🐛').replace(
|
result += f'{i}.{time_str}\n' + commit['commit']['message'].replace(':bug:', '🐛').replace(
|
||||||
':sparkles:', '✨').replace(':memo:', '📝') + '\n'
|
':sparkles:', '✨').replace(':memo:', '📝') + '\n'
|
||||||
return result
|
return result
|
||||||
@ -36,16 +39,28 @@ async def check_update():
|
|||||||
|
|
||||||
@run_sync
|
@run_sync
|
||||||
def update():
|
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:
|
try:
|
||||||
repo = git.Repo(Path().absolute())
|
repo = git.Repo(Path().absolute())
|
||||||
except InvalidGitRepositoryError:
|
except InvalidGitRepositoryError:
|
||||||
return '没有发现git仓库,无法通过git更新'
|
return '没有发现git仓库,无法通过git更新,请手动下载最新版本的文件进行替换。'
|
||||||
origin = repo.remotes.origin
|
origin = repo.remotes.origin
|
||||||
# repo.git.stash()
|
|
||||||
try:
|
try:
|
||||||
origin.pull()
|
origin.pull()
|
||||||
except GitCommandError as e:
|
except GitCommandError as e:
|
||||||
return f'更新失败,错误信息:{e},请手动进行更新'
|
if 'timeout' in e or 'unable to access' in e:
|
||||||
# finally:
|
return '更新失败,连接git仓库超时,请重试或修改源为代理源后再重试。'
|
||||||
# repo.git.stash('pop')
|
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}'
|
return f'更新完成,版本:{__version__}\n最新更新日志为:\n{repo.head.commit.message.replace(":bug:", "🐛").replace(":sparkles:", "✨").replace(":memo:", "📝")}\n可使用命令[@bot 重启]重启{NICKNAME}'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user