mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 23:51:21 +00:00
39 lines
1.2 KiB
Python
39 lines
1.2 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.CORSTermSocket,
|
|
{'term_manager': self.term_manager}
|
|
)]
|
|
)
|
|
|
|
@property
|
|
def pty(self):
|
|
return self.term_manager.terminal.ptyproc
|
|
|
|
class CORSTermSocket(TermSocket):
|
|
def check_origin(self, origin):
|
|
return True
|
|
|
|
def listen(self):
|
|
self.application.listen(self.port)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
log.info('Terminado Mini Server listening on {}'.format(tfwenv.TERMINADO_PORT))
|
|
TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']).listen()
|
|
IOLoop.instance().start()
|