From a4017ce872b685a26f31c5d3163c73dba9104fea Mon Sep 17 00:00:00 2001 From: ngfchl Date: Sat, 27 Aug 2022 12:09:42 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=A4=B1=E8=B4=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto_pt/views.py | 44 ++++++++----------- templates/auto_pt/restart.html | 78 ++++++++++++++++++++++++---------- 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/auto_pt/views.py b/auto_pt/views.py index 33a9b4a..e348f25 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -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): diff --git a/templates/auto_pt/restart.html b/templates/auto_pt/restart.html index ae4a4a1..d6afc76 100644 --- a/templates/auto_pt/restart.html +++ b/templates/auto_pt/restart.html @@ -19,27 +19,54 @@ {# #} - - {#
#} - {# {{ update_md|safe }}#} - {#
#} - - - -

-

-
+ + + +
+ 本地日志 +
+ + + +

+

+
-
-
-
+
+
+
+ + + +
+ 更新日志 +
+ + + +

+

+
+ +
+
+
+
+ @@ -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