mirror of https://github.com/openspug/spug
F 修复zsh批量执行异常问题 #522
parent
db38454787
commit
808ae4e679
|
@ -2,10 +2,12 @@
|
|||
# Copyright: (c) <spug.dev@gmail.com>
|
||||
# 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')
|
||||
|
|
|
@ -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 = ''
|
||||
|
|
Loading…
Reference in New Issue