From 2b306efb04664ba915d1f0d84025c4be46220879 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 24 Jan 2018 12:17:15 +0100 Subject: [PATCH] Refactor EventHandles supervisord access to a mixin --- lib/util.py | 9 +++++++-- src/event_handlers/source_code_event_handler.py | 10 +++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/util.py b/lib/util.py index 43a54c6..e7f0c6b 100644 --- a/lib/util.py +++ b/lib/util.py @@ -1,4 +1,6 @@ -import json +import json, xmlrpc.client + +from config.envvars import SUPERVISOR_HTTP_URI def parse_anchor_from_message(message): @@ -11,4 +13,7 @@ def create_source_code_response_data(filename, content, language): 'filename': filename, 'content': content, 'language': language - } \ No newline at end of file + } + +class SupervisorMixin: + supervisor = xmlrpc.client.ServerProxy(SUPERVISOR_HTTP_URI).supervisor \ No newline at end of file diff --git a/src/event_handlers/source_code_event_handler.py b/src/event_handlers/source_code_event_handler.py index 5096793..8fc5569 100644 --- a/src/event_handlers/source_code_event_handler.py +++ b/src/event_handlers/source_code_event_handler.py @@ -1,13 +1,12 @@ -import json from shutil import copy, rmtree, copytree from os.path import splitext -import xmlrpc.client -from config import SUPERVISOR_HTTP_URI, LOGIN_APP_DIR +from util import SupervisorMixin +from config import LOGIN_APP_DIR from event_handler_base import EventHandlerBase -class SourceCodeEventHandler(EventHandlerBase): +class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin): def __init__(self, anchor, filename, process_name=None, zmq_context=None): super().__init__(anchor, zmq_context) self.working_directory = LOGIN_APP_DIR @@ -19,9 +18,6 @@ class SourceCodeEventHandler(EventHandlerBase): 'write': self.write_file } - server = xmlrpc.client.ServerProxy(SUPERVISOR_HTTP_URI) - self.supervisor = server.supervisor - self.file = self.create_initial_state() def handle_event(self, anchor, data_json):