mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-09 02:07:17 +00:00
48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from tornado.ioloop import IOLoop
|
|
from tornado.web import Application
|
|
from terminado import TermSocket, SingleTermManager
|
|
|
|
from tfw.config import TFWENV
|
|
from tfw.config.logs import logging
|
|
|
|
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}
|
|
)]
|
|
)
|
|
|
|
@property
|
|
def term_manager(self):
|
|
return self._term_manager
|
|
|
|
@property
|
|
def pty(self):
|
|
return self.term_manager.terminal.ptyproc
|
|
|
|
class ResetterTermSocket(TermSocket):
|
|
def check_origin(self, origin):
|
|
return True
|
|
|
|
def on_close(self):
|
|
self.term_manager.terminal = None
|
|
self.term_manager.get_terminal()
|
|
|
|
def listen(self):
|
|
self.application.listen(self.port)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
LOG.info('Terminado Mini Server listening on %s', TFWENV.TERMINADO_PORT)
|
|
TerminadoMiniServer('/terminal', TFWENV.TERMINADO_PORT, TFWENV.TERMINADO_WD, ['bash']).listen()
|
|
IOLoop.instance().start()
|