def __init__(self, session, name=None, log_tag=None, restricted=False, initial_identity=None): self.session = session self.process = None self.stream = None self.stream_reader = None self.worker = None self.name = name self.log_tag = log_tag self.restricted = restricted self.initial_identity = initial_identity self.q_http_replies = BroadcastQueue() self.q_socket_messages = BroadcastQueue()
def __init__(self, manager=None, id=None, command=None, autoclose=False, autoclose_retain=5): self.width = 80 self.height = 25 self.id = id self.manager = manager self.autoclose = autoclose self.autoclose_retain = autoclose_retain self.output = BroadcastQueue() env = {} env.update(os.environ) env['TERM'] = 'linux' env['COLUMNS'] = str(self.width) env['LINES'] = str(self.height) env['LC_ALL'] = 'en_US.UTF8' self.command = command if not self.command: shell = os.environ.get('SHELL', None) if not shell: for sh in ['zsh', 'bash', 'sh']: try: shell = subprocess.check_output(['which', sh]) break except: pass self.command = shell args = ['sh', '-c', self.command] exe = 'sh' logging.info('Activating new terminal: %s', self.command) self.pid, self.fd = pty.fork() if self.pid == 0: setproctitle.setproctitle('%s terminal session #%i' % (sys.argv[0], os.getpid())) os.execvpe(exe, args, env) logging.info('Subprocess PID %s', self.pid) self.dead = False fl = fcntl.fcntl(self.fd, fcntl.F_GETFL) fcntl.fcntl(self.fd, fcntl.F_SETFL, fl | os.O_NONBLOCK) self.stream_in = os.fdopen(self.fd, 'rb', 0) self.stream_out = os.fdopen(self.fd, 'wb', 0) self.pyte_stream = pyte.Stream() self.screen = pyte.DiffScreen(self.width, self.height) self.pyte_stream.attach(self.screen) self.last_cursor_position = None self.reader = gevent.spawn(self.reader_fn)
def __init__(self, context): self.context = context self.tasks = {} self.notifications = BroadcastQueue()
def __init__(self, manager=None, id=None, command=None, autoclose=False, autoclose_retain=5, redirect=None): """ Setup the environment for a new terminal. :param manager: TerminalManager object :type manager: TerminalManager :param id: Id fo the terminal :type id: hex :param command: Command to run :type command: string :param autoclose: Parameter to close the terminal after the command :type autoclose: bool :param autoclose_retain: Time to wait before closing in seconds :type autoclose_retain: integer :param redirect: Default redirect URL after closing :type redirect: string """ self.width = 80 self.height = 25 self.id = id self.manager = manager self.autoclose = autoclose self.autoclose_retain = autoclose_retain if redirect: self.redirect = redirect else: self.redirect = '/view/terminal' self.output = BroadcastQueue() env = {} env.update(os.environ) env['TERM'] = 'linux' env['COLUMNS'] = str(self.width) env['LINES'] = str(self.height) env['LC_ALL'] = 'en_US.UTF8' self.command = command if not self.command: shell = os.environ.get('SHELL', None) if not shell: for sh in ['zsh', 'bash', 'sh']: try: shell = subprocess.check_output(['which', sh]) break except Exception as e: pass self.command = shell args = ['sh', '-c', self.command] exe = 'sh' logging.info(f'Activating new terminal: {self.command}') self.pid, self.fd = pty.fork() if self.pid == 0: setproctitle.setproctitle( f'{sys.argv[0]} terminal session #{os.getpid():d}') os.execvpe(exe, args, env) logging.info(f'Subprocess PID {self.pid}') self.dead = False fl = fcntl.fcntl(self.fd, fcntl.F_GETFL) fcntl.fcntl(self.fd, fcntl.F_SETFL, fl | os.O_NONBLOCK) self.stream_in = os.fdopen(self.fd, 'rb', 0) self.stream_out = os.fdopen(self.fd, 'wb', 0) self.pyte_stream = pyte.Stream() self.screen = pyte.DiffScreen(self.width, self.height) self.pyte_stream.attach(self.screen) self.last_cursor_position = None self.reader = gevent.spawn(self.reader_fn)
def __init__(self, context): self.q = BroadcastQueue()