From 36940ea3d4817b72f9c811a0339e649f4e919b53 Mon Sep 17 00:00:00 2001 From: ngfchl Date: Sat, 27 Aug 2022 11:15:02 +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 | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/auto_pt/views.py b/auto_pt/views.py index 90f5995..33a9b4a 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -93,8 +93,8 @@ def do_sql(request): def get_update(master='', n=10): # 获取最新的10条更新记录 - # master='' 本地 master='remote/' 远程 - p = subprocess.Popen('git log {}origin/master -{}'.format(master, n), shell=True, stdout=subprocess.PIPE, ) + # master='' 本地 master='origin/master' 远程 + p = subprocess.Popen('git log {} -{}'.format(master, n), shell=True, stdout=subprocess.PIPE, ) contents = p.stdout.readlines() update_notes = [] info = { @@ -138,24 +138,43 @@ def restart_container(request): def do_get_update(request): update = 'false' + # 拉取更新元数据 + 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, ) - 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: + commit = p.stdout.readline().decode('utf8') + print(commit) + if 'HEAD' in commit and 'origin' in commit: + return JsonResponse(data=CommonResponse.success( + msg='已经更新到最新!' + ).to_dict(), safe=False) + else: update = 'true' return JsonResponse(data=CommonResponse.success( msg='拉取更新日志成功!!', data={ 'update': update, - 'update_notes': get_update(master='remote/'), + 'update_notes': get_update(master='origin/master'), } ).to_dict(), safe=False) - return JsonResponse(data=CommonResponse.success( - msg='已经更新到最新!', - ).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): @@ -163,7 +182,6 @@ def do_update(request): print('更新') # print(os.system('cat ./update.sh')) subprocess.Popen('chmod +x ./update.sh', shell=True) - p = subprocess.Popen('./update.sh', shell=True, stdout=subprocess.PIPE, bufsize=1) p.wait() out = p.stdout.readlines() @@ -200,7 +218,7 @@ def do_restart(request): subprocess.Popen('chmod +x ./restart.sh', shell=True) subprocess.Popen('./restart.sh', shell=True) return JsonResponse(data=CommonResponse.success( - msg='重启指令发送成功!!' + msg='容器重启中!!' ).to_dict(), safe=False) return JsonResponse(data=CommonResponse.error( msg='未配置CONTAINER_NAME(容器名称)环境变量,请自行重启容器!!'