Loading cccli/commands/console.py +16 −9 Original line number Diff line number Diff line Loading @@ -7,26 +7,24 @@ CloudControl Console related commands from cccli.command import TqlCommand from cccli.exception import * from cccli.printer import Printer, color from sjrpc.core.exceptions import * from sjrpc.core.protocols import TunnelProtocol import fcntl import os import signal import struct import sys import termios import time import tty class FakeTtySocket(object): '''Give a tty a socket interface ''' Give a tty a socket interface This object cannot handle sigwinch directly because close can be called by remote RPC and by the way, called outside the main thread and fail. ''' def __init__(self): if not os.isatty(0): raise cmdError("stdin is not tty") Loading @@ -37,7 +35,9 @@ class FakeTtySocket(object): # set tty in raw mode tty.setraw(0) def recv(self, size): @staticmethod def recv(size): '''Emulate socket recv''' data = os.read(0, size) if "\x1d" in data: # return empty sting to simulate an EOF instead of raise Loading @@ -45,19 +45,26 @@ class FakeTtySocket(object): return "" return data def send(self, data): @staticmethod def send(data): '''Emulate socket send''' return os.write(0, data) def fileno(self): @staticmethod def fileno(): '''Emulate socket fileno''' return 0 def setblocking(self, blocking): @staticmethod def setblocking(*args): '''Emulate socket send''' # Do NOT be in non-blocking mode : non-blocking mode # causes rshell to get EAGAIN errors when having to # output loads of data, causing the TTY to break. return def close(self): '''Emulate socket close''' # reset tty original state termios.tcsetattr(0, termios.TCSADRAIN, self._tc_attr) Loading Loading
cccli/commands/console.py +16 −9 Original line number Diff line number Diff line Loading @@ -7,26 +7,24 @@ CloudControl Console related commands from cccli.command import TqlCommand from cccli.exception import * from cccli.printer import Printer, color from sjrpc.core.exceptions import * from sjrpc.core.protocols import TunnelProtocol import fcntl import os import signal import struct import sys import termios import time import tty class FakeTtySocket(object): '''Give a tty a socket interface ''' Give a tty a socket interface This object cannot handle sigwinch directly because close can be called by remote RPC and by the way, called outside the main thread and fail. ''' def __init__(self): if not os.isatty(0): raise cmdError("stdin is not tty") Loading @@ -37,7 +35,9 @@ class FakeTtySocket(object): # set tty in raw mode tty.setraw(0) def recv(self, size): @staticmethod def recv(size): '''Emulate socket recv''' data = os.read(0, size) if "\x1d" in data: # return empty sting to simulate an EOF instead of raise Loading @@ -45,19 +45,26 @@ class FakeTtySocket(object): return "" return data def send(self, data): @staticmethod def send(data): '''Emulate socket send''' return os.write(0, data) def fileno(self): @staticmethod def fileno(): '''Emulate socket fileno''' return 0 def setblocking(self, blocking): @staticmethod def setblocking(*args): '''Emulate socket send''' # Do NOT be in non-blocking mode : non-blocking mode # causes rshell to get EAGAIN errors when having to # output loads of data, causing the TTY to break. return def close(self): '''Emulate socket close''' # reset tty original state termios.tcsetattr(0, termios.TCSADRAIN, self._tc_attr) Loading