mirror of
https://github.com/ngfchl/ptools
synced 2023-07-10 13:41:22 +08:00
1. 修复获取更新失败的bug
This commit is contained in:
@@ -91,7 +91,7 @@ def do_sql(request):
|
||||
return JsonResponse('ok', safe=False)
|
||||
|
||||
|
||||
def get_update(master='', n=10):
|
||||
def get_git_logs(master='', n=10):
|
||||
# 获取最新的10条更新记录
|
||||
# master='' 本地 master='origin/master' 远程
|
||||
p = subprocess.Popen('git log {} -{}'.format(master, n), shell=True, stdout=subprocess.PIPE, )
|
||||
@@ -130,7 +130,7 @@ def restart_container(request):
|
||||
return render(request, 'auto_pt/restart.html',
|
||||
context={
|
||||
# 'update_md': update_md,
|
||||
'update_notes': get_update(),
|
||||
'local_logs': get_git_logs(),
|
||||
'restart': restart,
|
||||
'update': update,
|
||||
})
|
||||
@@ -141,13 +141,22 @@ def do_get_update(request):
|
||||
# 拉取更新元数据
|
||||
update_log = subprocess.Popen('git remote update', shell=True)
|
||||
update_log.wait()
|
||||
# 查看更新日志
|
||||
p = subprocess.Popen('git log origin/master -1', shell=True, stdout=subprocess.PIPE, )
|
||||
commit = p.stdout.readline().decode('utf8')
|
||||
print(commit)
|
||||
if 'HEAD' in commit and 'origin' in commit:
|
||||
# 获取本地更新日志第一条
|
||||
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:
|
||||
return JsonResponse(data=CommonResponse.success(
|
||||
msg='已经更新到最新!'
|
||||
msg='已经更新到最新!',
|
||||
data={
|
||||
'update_notes': get_git_logs(master='origin/master'),
|
||||
}
|
||||
).to_dict(), safe=False)
|
||||
else:
|
||||
update = 'true'
|
||||
@@ -155,26 +164,9 @@ def do_get_update(request):
|
||||
msg='拉取更新日志成功!!',
|
||||
data={
|
||||
'update': update,
|
||||
'update_notes': get_update(master='origin/master'),
|
||||
'update_notes': get_git_logs(master='origin/master'),
|
||||
}
|
||||
).to_dict(), safe=False)
|
||||
# content = p.stdout.readlines()
|
||||
# p_remote = subprocess.Popen('git log remote/origin/master -1', shell=True, stdout=subprocess.PIPE, )
|
||||
# content_remote = p_remote.stdout.readlines()
|
||||
# print(content)
|
||||
# print(content_remote)
|
||||
# if content_remote == content:
|
||||
# update = 'true'
|
||||
# return JsonResponse(data=CommonResponse.success(
|
||||
# msg='拉取更新日志成功!!',
|
||||
# data={
|
||||
# 'update': update,
|
||||
# 'update_notes': get_update(master='remote/'),
|
||||
# }
|
||||
# ).to_dict(), safe=False)
|
||||
# return JsonResponse(data=CommonResponse.success(
|
||||
# msg='已经更新到最新!',
|
||||
# ).to_dict(), safe=False)
|
||||
|
||||
|
||||
def do_update(request):
|
||||
|
||||
@@ -19,27 +19,54 @@
|
||||
{# <ul v-for="item in update_notes">#}
|
||||
{# <li v-html="item"></li>#}
|
||||
{# </ul>#}
|
||||
<el-card class="box-card">
|
||||
{# <div class="text item">#}
|
||||
{# {{ update_md|safe }}#}
|
||||
{# </div>#}
|
||||
<el-timeline>
|
||||
<el-timeline-item
|
||||
v-for="(update_note, index) in update_notes"
|
||||
:key="index"
|
||||
{# :icon="activity.icon"#}
|
||||
{# :type="activity.type"#}
|
||||
color="#0bbd87"
|
||||
{# :size="activity.size"#}
|
||||
:timestamp="update_note.date">
|
||||
<el-card>
|
||||
<p v-for="content in update_note.data" v-html="content">
|
||||
</p>
|
||||
</el-card>
|
||||
<el-row>
|
||||
<el-col :span="local_log_width">
|
||||
<el-card class="box-card">
|
||||
<div slot="header" class="clearfix">
|
||||
<span>本地日志</span>
|
||||
</div>
|
||||
<el-timeline>
|
||||
<el-timeline-item
|
||||
v-for="(update_note, index) in local_logs"
|
||||
:key="index"
|
||||
{# :icon="activity.icon"#}
|
||||
{# :type="activity.type"#}
|
||||
color="#0bbd87"
|
||||
{# :size="activity.size"#}
|
||||
:timestamp="update_note.date">
|
||||
<el-card>
|
||||
<p v-for="content in update_note.data" v-html="content">
|
||||
</p>
|
||||
</el-card>
|
||||
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
</el-card>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12" v-if="update_log">
|
||||
<el-card class="box-card">
|
||||
<div slot="header" class="clearfix">
|
||||
<span>更新日志</span>
|
||||
</div>
|
||||
<el-timeline>
|
||||
<el-timeline-item
|
||||
v-for="(update_note, index) in update_notes"
|
||||
:key="index"
|
||||
{# :icon="activity.icon"#}
|
||||
{# :type="activity.type"#}
|
||||
color="#0bbd87"
|
||||
{# :size="activity.size"#}
|
||||
:timestamp="update_note.date">
|
||||
<el-card>
|
||||
<p v-for="content in update_note.data" v-html="content">
|
||||
</p>
|
||||
</el-card>
|
||||
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
</div>
|
||||
</el-card>
|
||||
@@ -56,9 +83,12 @@
|
||||
// element: 指定用vue来管理页面中的哪个标签区域
|
||||
el: '#app',
|
||||
data: {
|
||||
update_notes: {{ update_notes|safe }},
|
||||
update_notes: '',
|
||||
local_logs: {{ local_logs|safe }},
|
||||
restart:{{ restart }},
|
||||
update:{{ update }}
|
||||
update:{{ update }},
|
||||
update_log: false,
|
||||
local_log_width: 24
|
||||
},
|
||||
methods: {
|
||||
do_restart() {
|
||||
@@ -104,6 +134,10 @@
|
||||
"{% url "do_get_update" %}"
|
||||
).then(res => {
|
||||
if (res.data.code === 0) {
|
||||
console.log(res.data)
|
||||
this.update_notes = res.data.data.update_notes
|
||||
this.update_log = true
|
||||
this.local_log_width = 12
|
||||
this.$message({
|
||||
type: 'success',
|
||||
message: res.data.msg
|
||||
|
||||
Reference in New Issue
Block a user