update connect.py

pull/26/head
kelianchun_miller 9 years ago
parent 55503c89e9
commit 0c42d039ff

@ -178,8 +178,6 @@ class Tty(object):
VIM_FLAG = True VIM_FLAG = True
return result_command.decode('utf8',"ignore") return result_command.decode('utf8',"ignore")
else: else:
if result_command.endswith(':wq') or result_command.endswith(':wq!') or result_command.endswith(':q!'):
VIM_FLAG = False
return '' return ''
@staticmethod @staticmethod
@ -338,8 +336,11 @@ class SshTty(Tty):
log_file_f, log_time_f, log = self.get_log() log_file_f, log_time_f, log = self.get_log()
old_tty = termios.tcgetattr(sys.stdin) old_tty = termios.tcgetattr(sys.stdin)
pre_timestamp = time.time() pre_timestamp = time.time()
pattern = re.compile('\[.*@.*\][\$#]')
data = '' data = ''
chan_str = ''
input_mode = False input_mode = False
global VIM_FLAG
try: try:
tty.setraw(sys.stdin.fileno()) tty.setraw(sys.stdin.fileno())
@ -357,6 +358,8 @@ class SshTty(Tty):
x = self.channel.recv(1024) x = self.channel.recv(1024)
if len(x) == 0: if len(x) == 0:
break break
if VIM_FLAG:
chan_str += x
sys.stdout.write(x) sys.stdout.write(x)
sys.stdout.flush() sys.stdout.flush()
now_timestamp = time.time() now_timestamp = time.time()
@ -377,10 +380,19 @@ class SshTty(Tty):
input_mode = True input_mode = True
if str(x) in ['\r', '\n', '\r\n']: if str(x) in ['\r', '\n', '\r\n']:
data = self.deal_command(data, self.ssh) if VIM_FLAG:
match = pattern.search(chan_str)
TtyLog(log=log, datetime=datetime.datetime.now(), cmd=data).save() if match:
VIM_FLAG = False
data = self.deal_command(data, self.ssh)
if len(data) > 0:
TtyLog(log=log, datetime=datetime.datetime.now(), cmd=data).save()
else:
data = self.deal_command(data, self.ssh)
if len(data) > 0:
TtyLog(log=log, datetime=datetime.datetime.now(), cmd=data).save()
data = '' data = ''
chan_str = ''
input_mode = False input_mode = False
if len(x) == 0: if len(x) == 0:

Loading…
Cancel
Save