mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:31:31 +00:00
Refactor of writing/reading in SourceCodeEventHandler.handle_event()
This commit is contained in:
parent
70a2dd1de6
commit
2793efeaf9
@ -25,6 +25,12 @@ class SourceCodeEventHandler(EventHandlerBase):
|
|||||||
if anchor == b'reset':
|
if anchor == b'reset':
|
||||||
self.file = self.create_initial_state(process_is_running=True)
|
self.file = self.create_initial_state(process_is_running=True)
|
||||||
if data['command'] == 'read':
|
if data['command'] == 'read':
|
||||||
|
self.read_file(data_json)
|
||||||
|
elif data['command'] == 'write':
|
||||||
|
self.write_file(data)
|
||||||
|
return data_json
|
||||||
|
|
||||||
|
def read_file(self, data_json):
|
||||||
with open(self.file, 'r') as ifile:
|
with open(self.file, 'r') as ifile:
|
||||||
content = ifile.read()
|
content = ifile.read()
|
||||||
data_json['data'] = {
|
data_json['data'] = {
|
||||||
@ -32,13 +38,12 @@ class SourceCodeEventHandler(EventHandlerBase):
|
|||||||
'content': content,
|
'content': content,
|
||||||
'language': self.language
|
'language': self.language
|
||||||
}
|
}
|
||||||
return data_json
|
|
||||||
elif data['command'] == 'write':
|
def write_file(self, data):
|
||||||
with open(self.file, 'w') as ofile:
|
with open(self.file, 'w') as ofile:
|
||||||
ofile.write(data['content'])
|
ofile.write(data['content'])
|
||||||
self.supervisor.stopProcess(self.process_name)
|
self.supervisor.stopProcess(self.process_name)
|
||||||
self.supervisor.startProcess(self.process_name)
|
self.supervisor.startProcess(self.process_name)
|
||||||
return None
|
|
||||||
|
|
||||||
def create_initial_state(self, process_is_running=False):
|
def create_initial_state(self, process_is_running=False):
|
||||||
if process_is_running:
|
if process_is_running:
|
||||||
|
Loading…
Reference in New Issue
Block a user