def posix_shell(chan,channel,log_name=None,width=90,height=40):
from OpsManage.asgi import channel_layer
stdout = list()
begin_time = time.time()
last_write_time = {'last_activity_time':begin_time}
try:
chan.settimeout(0.0)
while True:
try:
x = u(chan.recv(1024))
if len(x) == 0:
channel_layer.send(channel, {'text': json.dumps(['disconnect',smart_unicode('\r\n*** EOF\r\n')]) })
break
now = time.time()
delay = now - last_write_time['last_activity_time']
last_write_time['last_activity_time'] = now
if x == "exit\r\n" or x == "logout\r\n" or x == 'logout':
chan.close()
else:
stdout.append([delay,codecs.getincrementaldecoder('UTF-8')('replace').decode(x)])
channel_layer.send(channel, {'text': json.dumps(['stdout',smart_unicode(x)]) })
except socket.timeout:
pass
except Exception,e:
channel_layer.send(channel, {'text': json.dumps(['stdout','A bug find,You can report it to me' + smart_unicode(e)]) })
finally:
pass
评论列表
文章目录