Fix terminado buffer issues & terminado server OO refactor

This commit is contained in:
Kristóf Tóth 2018-01-25 16:48:48 +01:00
parent 8244e22479
commit 96b5234fc1
2 changed files with 22 additions and 21 deletions

View File

@ -1,7 +1,5 @@
import logging import logging
from shutil import rmtree, copytree from shutil import rmtree, copytree
from xmlrpc.client import Fault as SupervisorFault
from contextlib import suppress
from event_handler_base import EventHandlerBase from event_handler_base import EventHandlerBase
from util import SupervisorMixin from util import SupervisorMixin
@ -23,8 +21,3 @@ class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
def handle_event(self, anchor, data_json): def handle_event(self, anchor, data_json):
logging.debug('TerminadoEventHandler received event for anchor {}'.format(anchor)) logging.debug('TerminadoEventHandler received event for anchor {}'.format(anchor))
# TODO: wat do? # TODO: wat do?
def handle_reset(self, data_json):
with suppress(SupervisorFault):
self.supervisor.stopProcess(self.process_name)
self.supervisor.startProcess(self.process_name)

View File

@ -1,25 +1,33 @@
import logging import logging
from tornado.ioloop import IOLoop from tornado.ioloop import IOLoop
from tornado.web import Application from tornado.web import Application
from terminado import TermSocket, SingleTermManager from terminado import TermSocket, UniqueTermManager
from config import TERMINADO_PORT, TERMINADO_WD from config import TERMINADO_PORT, TERMINADO_WD
class CORSTermSocket(TermSocket): class TerminadoMiniServer:
def check_origin(self, origin): def __init__(self, url, port, workdir, shellcmd):
return True 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__': if __name__ == '__main__':
application = Application(
[(
r'/terminal',
CORSTermSocket,
{'term_manager': SingleTermManager(shell_command=['bash'],
term_settings={'cwd': TERMINADO_WD})}
)]
)
application.listen(TERMINADO_PORT)
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
logging.info('Terminado Mini Server listening on {}'.format(TERMINADO_PORT)) logging.info('Terminado Mini Server listening on {}'.format(TERMINADO_PORT))
IOLoop.instance().start() TerminadoMiniServer('/terminal', TERMINADO_PORT, TERMINADO_WD, ['bash']).listen()