Implement history reading API

This commit is contained in:
Kristóf Tóth 2018-03-03 22:46:14 +01:00
parent 5133806d33
commit 180cf41f85
2 changed files with 14 additions and 3 deletions

View File

@ -60,7 +60,9 @@ ENV PYTHONPATH="/usr/local/lib/" \
TFW_LIB_DIR="/usr/local/lib/" \ TFW_LIB_DIR="/usr/local/lib/" \
TFW_CONTROLLER_DIR="/srv/controller" \ TFW_CONTROLLER_DIR="/srv/controller" \
TFW_TERMINADO_DIR="/tmp/terminado_server" \ TFW_TERMINADO_DIR="/tmp/terminado_server" \
TFW_FRONTEND_DIR="/srv/frontend" TFW_FRONTEND_DIR="/srv/frontend" \
TFW_HISTFILE="/home/${AVATAO_USER}/.bash_history" \
PROMPT_COMMAND="history -a"
COPY nginx/nginx.conf ${TFW_NGINX_CONF} COPY nginx/nginx.conf ${TFW_NGINX_CONF}
COPY nginx/components/ ${TFW_NGINX_COMPONENTS} COPY nginx/components/ ${TFW_NGINX_COMPONENTS}

View File

@ -1,4 +1,5 @@
from tfw.components.terminado_mini_server import TerminadoMiniServer from tfw.components.terminado_mini_server import TerminadoMiniServer
from tfw.components.history_monitor import HistoryMonitor
from tfw.event_handler_base import TriggerlessEventHandler from tfw.event_handler_base import TriggerlessEventHandler
from tfw.config import tfwenv from tfw.config import tfwenv
from tfw.config.logs import logging from tfw.config.logs import logging
@ -9,14 +10,22 @@ class TerminadoEventHandler(TriggerlessEventHandler):
def __init__(self, key): def __init__(self, key):
super().__init__(key) super().__init__(key)
self.working_directory = tfwenv.TERMINADO_DIR self.working_directory = tfwenv.TERMINADO_DIR
self.monitor = HistoryMonitor(tfwenv.HISTFILE)
self.terminado_server = TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash']) self.terminado_server = TerminadoMiniServer('/terminal', tfwenv.TERMINADO_PORT, tfwenv.TERMINADO_WD, ['bash'])
self.commands = {'write': self.write} self.commands = {'write': self.write,
'read': self.read}
self.monitor.watch()
self.terminado_server.listen() self.terminado_server.listen()
def handle_event(self, key, data_json): def handle_event(self, key, data_json):
log.debug('TerminadoEventHandler received event: {}'.format(data_json)) log.debug('TerminadoEventHandler received event: {}'.format(data_json))
data = data_json['data'] data = data_json['data']
self.commands[data['command']](data) data_json['data'] = self.commands[data['command']](data)
return data_json
def write(self, data): def write(self, data):
self.terminado_server.pty.write(data['shellcmd']) self.terminado_server.pty.write(data['shellcmd'])
def read(self, data):
data['history'] = self.monitor.history[-int(data.get('count', 1)):]
return data