mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-12-22 22:21:56 +00:00
Refactor handling of working directory for SourceCodeEventHandler
This commit is contained in:
parent
89694097cc
commit
dceb3b947f
@ -51,7 +51,8 @@ ENV TFW_APP_DIR="/srv/app"
|
||||
ENV TFW_FRONTEND_DIR="/srv/frontend"
|
||||
ENV TFW_LOGIN_APP_DIR="/tmp/source_code_server"
|
||||
ENV TFW_TERMINADO_DIR="/tmp/terminado_server"
|
||||
ENV TFW_TERMINADO_WD="/home/${AVATAO_USER}"
|
||||
ENV TFW_WEBIDE_WD="/home/${AVATAO_USER}/workdir"
|
||||
ENV TFW_TERMINADO_WD=${TFW_WEBIDE_WD}
|
||||
ENV TFW_LIB_DIR="/usr/local/lib/"
|
||||
ENV TFW_SUPERVISORD_CONF="/etc/supervisor/supervisord.conf"
|
||||
ENV TFW_SUPERVISORD_COMPONENTS="/etc/supervisor/conf"
|
||||
@ -75,6 +76,12 @@ COPY src/event_handlers ${TFW_EVENT_HANDLERS_DIR}
|
||||
|
||||
RUN mv /data/dist ${TFW_FRONTEND_DIR}
|
||||
|
||||
COPY src/event_handlers/source_code_server/server.py ${TFW_LOGIN_APP_DIR}/
|
||||
COPY src/event_handlers/source_code_server/users.db ${TFW_LOGIN_APP_DIR}/
|
||||
COPY src/event_handlers/source_code_server/login_component.py ${TFW_WEBIDE_WD}/
|
||||
|
||||
RUN chown -R ${AVATAO_USER} ${TFW_WEBIDE_WD}
|
||||
|
||||
USER ${AVATAO_USER}
|
||||
WORKDIR /home/${AVATAO_USER}
|
||||
|
||||
|
@ -7,6 +7,7 @@ SUPERVISOR_HTTP_PORT = os.getenv('TFW_SUPERVISOR_PORT', 9001)
|
||||
LOGIN_APP_PORT = os.getenv('TFW_LOGIN_APP_PORT', 6666)
|
||||
TERMINADO_PORT = os.getenv('TFW_TERMINADO_PORT', 9999)
|
||||
TERMINADO_WD = os.getenv('TFW_TERMINADO_WD')
|
||||
WEBIDE_WD = os.getenv('TFW_WEBIDE_WD')
|
||||
|
||||
SUPERVISOR_HTTP_URI = 'http://localhost:{}'.format(SUPERVISOR_HTTP_PORT)
|
||||
|
||||
|
@ -2,8 +2,10 @@ from source_code_event_handler import SourceCodeEventHandler
|
||||
from terminado_event_handler import TerminadoEventHandler
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
from tfw.config.envvars import WEBIDE_WD
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
anchor_webide = SourceCodeEventHandler('anchor_webide', 'login_projectdir', 'login')
|
||||
anchor_webide = SourceCodeEventHandler('anchor_webide', WEBIDE_WD, 'login')
|
||||
anchor_terminado = TerminadoEventHandler('anchor_terminado', 'terminado')
|
||||
IOLoop.instance().start()
|
||||
|
@ -1,9 +1,7 @@
|
||||
from shutil import copy, rmtree, copytree
|
||||
from os.path import splitext, isfile, join, relpath
|
||||
from glob import glob
|
||||
|
||||
from tfw.util import SupervisorMixin
|
||||
from tfw.config import LOGIN_APP_DIR
|
||||
from tfw.event_handler_base import EventHandlerBase
|
||||
|
||||
from tfw.config.logs import logging
|
||||
@ -11,10 +9,8 @@ log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class FileManager:
|
||||
def __init__(self, source_directory, working_directory, selected_file=None):
|
||||
self._sourcedir = source_directory
|
||||
def __init__(self, working_directory, selected_file=None):
|
||||
self._workdir = working_directory
|
||||
self._reload_files()
|
||||
self.filename = selected_file or self._relpath(self.files[0])
|
||||
self.language = map_file_extension_to_language(self.filename)
|
||||
|
||||
@ -44,15 +40,11 @@ class FileManager:
|
||||
def _relpath(self, filename):
|
||||
return relpath(self._filepath(filename), start=self._workdir)
|
||||
|
||||
def _reload_files(self):
|
||||
rmtree(self._workdir, ignore_errors=True)
|
||||
copytree(self._sourcedir, self._workdir)
|
||||
|
||||
|
||||
class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
|
||||
def __init__(self, anchor, directory, process_name=None, selected_file=None):
|
||||
super().__init__(anchor)
|
||||
self.filemanager = FileManager(directory, LOGIN_APP_DIR, selected_file=selected_file)
|
||||
self.filemanager = FileManager(directory, selected_file=selected_file)
|
||||
self.process_name = process_name
|
||||
|
||||
self.commands = {
|
||||
@ -61,10 +53,6 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
|
||||
'select': self.select
|
||||
}
|
||||
|
||||
# Supervisor needs these to run the login program
|
||||
copy('source_code_server/server.py', LOGIN_APP_DIR)
|
||||
copy('source_code_server/users.db', LOGIN_APP_DIR)
|
||||
|
||||
def read(self, data):
|
||||
data['filename'] = self.filemanager.filename
|
||||
data['content'] = self.filemanager.file_contents
|
||||
|
@ -1,9 +1,10 @@
|
||||
import json
|
||||
|
||||
import json, sys
|
||||
from tornado.ioloop import IOLoop
|
||||
from tornado.web import RequestHandler, Application
|
||||
|
||||
from tfw.config import LOGIN_APP_PORT
|
||||
from tfw.config import LOGIN_APP_PORT, WEBIDE_WD
|
||||
|
||||
sys.path.append(WEBIDE_WD)
|
||||
from login_component import authorize_login
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user