From 808ae4e679ac7d9f508165a403df0ee6f7b16a2a Mon Sep 17 00:00:00 2001 From: vapao Date: Thu, 14 Jul 2022 23:38:40 +0800 Subject: [PATCH] =?UTF-8?q?F=20=E4=BF=AE=E5=A4=8Dzsh=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=89=A7=E8=A1=8C=E5=BC=82=E5=B8=B8=E9=97=AE=E9=A2=98=20#522?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/exec/executors.py | 5 +++++ spug_api/libs/ssh.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/spug_api/apps/exec/executors.py b/spug_api/apps/exec/executors.py index 94b1147..5950f49 100644 --- a/spug_api/apps/exec/executors.py +++ b/spug_api/apps/exec/executors.py @@ -2,10 +2,12 @@ # Copyright: (c) # Released under the AGPL-3.0 License. from django_redis import get_redis_connection +from libs.utils import human_seconds_time from libs.ssh import SSH import threading import socket import json +import time def exec_worker_handler(job): @@ -51,12 +53,15 @@ class Job: if not self.token: with self.ssh: return self.ssh.exec_command(self.command, self.env) + flag = time.time() self.send('\r\n\x1b[36m### Executing ...\x1b[0m\r\n') code = -1 try: with self.ssh: for code, out in self.ssh.exec_command_with_stream(self.command, self.env): self.send(out) + human_time = human_seconds_time(time.time() - flag) + self.send(f'\r\n\x1b[36m** 执行结束,总耗时:{human_time} **\x1b[0m') except socket.timeout: code = 130 self.send('\r\n\x1b[31m### Time out\x1b[0m') diff --git a/spug_api/libs/ssh.py b/spug_api/libs/ssh.py index 7ffa677..324c1ba 100644 --- a/spug_api/libs/ssh.py +++ b/spug_api/libs/ssh.py @@ -181,7 +181,8 @@ class SSH: counter = 0 self.channel = self.client.invoke_shell(**self.term) - command = 'set +o history\nset +o zle\nset -o no_nomatch\nexport PS1= && stty -echo\n' + command = 'set +o zle\n[ -n "$BASH_VERSION" ] && set +o history\n[ -n "$ZSH_VERSION" ] && set -o no_nomatch\n' + command += 'export PS1= && stty -echo\n' command = self._handle_command(command, self.default_env) self.channel.sendall(command) out = ''