baseimage-tutorial-framework/tfw/components/terminal/terminado_mini_server.py

41 lines
1.1 KiB
Python
Raw Normal View History

2019-06-10 13:32:45 +00:00
import logging
from tornado.web import Application
from terminado import TermSocket, SingleTermManager
LOG = logging.getLogger(__name__)
class TerminadoMiniServer:
def __init__(self, url, port, workdir, shellcmd):
self.port = port
self._term_manager = SingleTermManager(
shell_command=shellcmd,
term_settings={'cwd': workdir}
)
self.application = Application([(
url,
TerminadoMiniServer.ResetterTermSocket,
{'term_manager': self._term_manager}
2020-05-18 16:02:07 +00:00
)], websocket_ping_interval=30)
@property
def term_manager(self):
return self._term_manager
@property
def pty(self):
if self.term_manager.terminal is None:
self.term_manager.get_terminal()
return self.term_manager.terminal.ptyproc
class ResetterTermSocket(TermSocket): # pylint: disable=abstract-method
def check_origin(self, origin):
return True
def listen(self):
self.application.listen(self.port)
2019-05-31 11:10:33 +00:00
def stop(self):
self.term_manager.shutdown()