1. 优化更新流程,自动获取更新信息并展示,用户自行决定是否升级

This commit is contained in:
ngfchl
2022-08-27 16:19:45 +08:00
parent de4a4f476b
commit 2d251f48e5
3 changed files with 55 additions and 9 deletions

View File

@@ -123,16 +123,36 @@ def restart_container(request):
# res = scraper.get('https://gitee.com/ngfchl/ptools/raw/master/update.md')
# update_md = markdown.markdown(res.text, extensions=['tables'])
# 拉取更新元数据
update_log = subprocess.Popen('git remote update', shell=True)
update_log.wait()
# 获取本地更新日志第一条
p_local = subprocess.Popen('git log --oneline -1', shell=True, stdout=subprocess.PIPE, )
commit_local = p_local.stdout.readline().decode('utf8').strip()
# 获取远端仓库更新日志第一条
p_remote = subprocess.Popen('git log origin/master --oneline -1', shell=True, stdout=subprocess.PIPE, )
commit_remote = p_remote.stdout.readline().decode('utf8').strip()
print(commit_local, commit_remote)
# if 'HEAD' in commit and 'origin' in commit:
print(commit_remote == commit_local)
# 如果日志相同则更新到最新,否则显示远端更新日志
if commit_remote == commit_local:
update = 'false'
update_tips = '目前您使用的是最新版本!'
else:
update = 'true'
update_tips = '已有新版本,请根据需要升级!'
restart = 'false'
update = 'false'
if os.environ.get('CONTAINER_NAME'):
restart = 'true'
return render(request, 'auto_pt/restart.html',
context={
# 'update_md': update_md,
'local_logs': get_git_logs(),
'update_notes': get_git_logs(master='origin/master'),
'restart': restart,
'update': update,
'update_tips': update_tips,
})

View File

@@ -9,7 +9,6 @@
<el-card class="box-card">
<div slot="header" class="clearfix">
<span>
<el-popover
placement="top-start"
title="友情提示"
@@ -18,9 +17,12 @@
content="如果遇到无法更新的情况,您可以选择重建容器或者进入容器命令行到项目根目录执行`git pull`命令!">
<el-button slot="reference">更新提示</el-button>
</el-popover>
<el-link type="success">{{ update_tips }}</el-link>
</span>
<span style="float: right;margin-top: -10px">
<el-button type="primary" @click="get_update">获取更新</el-button>
{# <el-button type="primary" @click="get_update">获取更新</el-button>#}
<el-button type="success" @click="do_update" v-if="update">更新</el-button>
<el-button type="danger" @click="do_restart" v-if="restart">重启</el-button>
</span>
@@ -50,7 +52,7 @@
</el-timeline>
</el-card>
</el-col>
<el-col :span="12" v-if="update_log">
<el-col :span="12" v-if="update">
<el-card class="box-card" shadow="hover">
<div slot="header" class="clearfix">
<span>更新日志</span>
@@ -90,13 +92,28 @@
// element: 指定用vue来管理页面中的哪个标签区域
el: '#app',
data: {
update_notes: '',
update_notes: {{ update_notes|safe }},
local_logs: {{ local_logs|safe }},
restart:{{ restart }},
update:{{ update }},
update_log: false,
update: false,
{#update_log: false,#}
local_log_width: 24
},
created() {
this.update =
{{ update }}
if (this.update) {
this.local_log_width = 12
}
this.$message({
showClose: true,
message: "{{ update_tips }}",
type: 'success'
});
},
methods: {
do_restart() {
this.$confirm('此操作将重启容器,并更新软件, 是否继续?', '提示', {
@@ -143,7 +160,7 @@
if (res.data.code === 0) {
console.log(res.data)
this.update_notes = res.data.data.update_notes
this.update_log = true
{#this.update_log = true#}
this.local_log_width = 12
this.$message({
type: 'success',

View File

@@ -7,6 +7,15 @@
### 更新修复
- 0827
1. 修复部分导入导出失败的错误
2. 修复带逗号的魔力值解析错误的bug
3. 修复获取更新失败的bug
4. 修复删除站点时权限拒绝的bug
5. 修复PT时间刷新状态时报错的bug
6. 优化更新界面,增加提示信息
7. 优化更新流程,自动获取更新信息并展示,用户自行决定是否升级
- 0826
1. 修复白兔签到返回错误的bug
2. 修复容器名称与环境变量已正确显示无法重启的bug
@@ -14,4 +23,4 @@
4. 更新功能中加入规则更新,直接写入数据库(写入前备份)
5. 更新部分站点规则
6. 修复容器名称与环境变量已正确设置但无法重启的bug
7. 优化重启按钮在环境变量CONTAINER_NAME未设置时不显示
7. 优化重启按钮在环境变量CONTAINER_NAME未设置时不显示