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

34 lines
1.0 KiB
Python
Raw Normal View History

from tornado.ioloop import IOLoop
from tornado.web import Application
from terminado import TermSocket, UniqueTermManager
from tfw.config import tfwenv
2018-01-31 14:50:52 +00:00
from tfw.config.logs import logging
2018-01-29 17:36:29 +00:00
log = logging.getLogger(__name__)
class TerminadoMiniServer:
def __init__(self, url, port, workdir, shellcmd):
self.port = port
self.application = Application(
[(
url,
TerminadoMiniServer.CORSTermSocket,
{'term_manager': UniqueTermManager(shell_command=shellcmd,
term_settings={'cwd': workdir})}
)]
)
class CORSTermSocket(TermSocket):
def check_origin(self, origin):
return True
def listen(self):
self.application.listen(self.port)
IOLoop.instance().start()
if __name__ == '__main__':
log.info('Terminado Mini Server listening on {}'.format(tfwenv.TERMINADO_PORT))
TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']).listen()