mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 11:52:54 +00:00 
			
		
		
		
	Implement and integrate TerminadoEvendHandler to docker container
This commit is contained in:
		@@ -5,6 +5,7 @@ from functools import partial
 | 
			
		||||
import source_code
 | 
			
		||||
from event_handler_base import EventHandlerBase
 | 
			
		||||
from source_code_event_handler import SourceCodeEventHandler
 | 
			
		||||
from terminado_event_handler import TerminadoEventHandler
 | 
			
		||||
from tornado.ioloop import IOLoop
 | 
			
		||||
 | 
			
		||||
from login_component import authorize_login
 | 
			
		||||
@@ -86,5 +87,6 @@ if __name__ == '__main__':
 | 
			
		||||
    anchor_b = Rot13Handler('anchor_b')
 | 
			
		||||
    anchor_c = ReverseHandler('anchor_c')
 | 
			
		||||
    anchor_webide = SourceCodeEventHandler('anchor_webide', 'login_component.py', 'login')
 | 
			
		||||
    anchor_terminado = TerminadoEventHandler('anchor_terminado', 'terminado')
 | 
			
		||||
    IOLoop.instance().start()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,33 +1,21 @@
 | 
			
		||||
import logging
 | 
			
		||||
from shutil import rmtree, copytree
 | 
			
		||||
 | 
			
		||||
from event_handler_base import EventHandlerBase
 | 
			
		||||
from tornado.ioloop import IOLoop
 | 
			
		||||
from tornado.web import Application
 | 
			
		||||
from terminado import TermSocket, SingleTermManager
 | 
			
		||||
from util import SupervisorMixin
 | 
			
		||||
from config import TERMINADO_DIR
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CORSTermSocket(TermSocket):
 | 
			
		||||
    def check_origin(self, origin):
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TerminadoEventHandler(EventHandlerBase):
 | 
			
		||||
    def __init__(self, anchor, zmq_context=None):
 | 
			
		||||
class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
 | 
			
		||||
    def __init__(self, anchor, process_name, zmq_context=None):
 | 
			
		||||
        super().__init__(anchor, zmq_context)
 | 
			
		||||
        self.working_directory = TERMINADO_DIR
 | 
			
		||||
        self.process_name = process_name
 | 
			
		||||
        self.setup_terminado_server()
 | 
			
		||||
 | 
			
		||||
    def setup_terminado_server(self):
 | 
			
		||||
        rmtree(self.working_directory, ignore_errors=True)
 | 
			
		||||
        copytree('terminado_server/', self.working_directory)
 | 
			
		||||
        self.supervisor.startProcess(self.process_name)
 | 
			
		||||
 | 
			
		||||
    def handle_event(self, anchor, data_json):
 | 
			
		||||
        raise NotImplementedError   # TODO: wat do?
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    application = Application(
 | 
			
		||||
        [(
 | 
			
		||||
            r'/terminal',
 | 
			
		||||
            CORSTermSocket,
 | 
			
		||||
            {'term_manager': SingleTermManager(shell_command=['bash'])}
 | 
			
		||||
        )]
 | 
			
		||||
    )
 | 
			
		||||
    HOST, PORT = 'localhost', 7878
 | 
			
		||||
    application.listen(PORT, HOST)
 | 
			
		||||
    logging.getLogger().setLevel(logging.DEBUG)
 | 
			
		||||
    logging.info('Terminado Mini Server listening on {}:{}'.format(HOST, PORT))
 | 
			
		||||
    IOLoop.instance().start()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										24
									
								
								src/event_handlers/terminado_server/server.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/event_handlers/terminado_server/server.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
import logging
 | 
			
		||||
from tornado.ioloop import IOLoop
 | 
			
		||||
from tornado.web import Application
 | 
			
		||||
from terminado import TermSocket, SingleTermManager
 | 
			
		||||
 | 
			
		||||
from config import TERMINADO_PORT
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class CORSTermSocket(TermSocket):
 | 
			
		||||
    def check_origin(self, origin):
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    application = Application(
 | 
			
		||||
        [(
 | 
			
		||||
            r'/terminal',
 | 
			
		||||
            CORSTermSocket,
 | 
			
		||||
            {'term_manager': SingleTermManager(shell_command=['bash'])}
 | 
			
		||||
        )]
 | 
			
		||||
    )
 | 
			
		||||
    application.listen(TERMINADO_PORT)
 | 
			
		||||
    logging.getLogger().setLevel(logging.DEBUG)
 | 
			
		||||
    logging.info('Terminado Mini Server listening on {}'.format(TERMINADO_PORT))
 | 
			
		||||
    IOLoop.instance().start()
 | 
			
		||||
		Reference in New Issue
	
	Block a user