Refactor for handling xmlrpc exceptiions

This commit is contained in:
Kristóf Tóth 2018-01-24 15:54:03 +01:00
parent 83b66c47b5
commit c7bc588397
2 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,6 @@
from shutil import copy, rmtree, copytree from shutil import copy, rmtree, copytree
from os.path import splitext from os.path import splitext
from xmlrpc.client import Fault as SupervisorFault
from util import SupervisorMixin from util import SupervisorMixin
from config import LOGIN_APP_DIR from config import LOGIN_APP_DIR
@ -26,7 +27,7 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
return data_json return data_json
def handle_reset(self, data_json): def handle_reset(self, data_json):
self.create_initial_state(process_is_running=True) self.create_initial_state()
def read_file(self, data_json): def read_file(self, data_json):
with open(self.file, 'r') as ifile: with open(self.file, 'r') as ifile:
@ -44,9 +45,9 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
self.supervisor.stopProcess(self.process_name) self.supervisor.stopProcess(self.process_name)
self.supervisor.startProcess(self.process_name) self.supervisor.startProcess(self.process_name)
def create_initial_state(self, process_is_running=False): def create_initial_state(self):
if process_is_running: try: self.supervisor.stopProcess(self.process_name)
self.supervisor.stopProcess(self.process_name) except SupervisorFault: pass
rmtree(self.working_directory, ignore_errors=True) rmtree(self.working_directory, ignore_errors=True)
copytree('source_code_server/', self.working_directory) copytree('source_code_server/', self.working_directory)

View File

@ -1,4 +1,5 @@
from shutil import rmtree, copytree from shutil import rmtree, copytree
from xmlrpc.client import Fault as SupervisorFault
from event_handler_base import EventHandlerBase from event_handler_base import EventHandlerBase
from util import SupervisorMixin from util import SupervisorMixin
@ -19,3 +20,8 @@ class TerminadoEventHandler(EventHandlerBase, SupervisorMixin):
def handle_event(self, anchor, data_json): def handle_event(self, anchor, data_json):
raise NotImplementedError # TODO: wat do? raise NotImplementedError # TODO: wat do?
def handle_reset(self, data_json):
try: self.supervisor.stopProcess(self.process_name)
except SupervisorFault: pass
self.supervisor.startProcess(self.process_name)