Make SourceCodeEventHandler command handlers data_json['data'] based

This commit is contained in:
Kristóf Tóth 2018-02-08 15:10:37 +01:00
parent 6283b825d6
commit 792981742c

View File

@ -65,28 +65,27 @@ class SourceCodeEventHandler(EventHandlerBase, SupervisorMixin):
copy('source_code_server/server.py', LOGIN_APP_DIR) copy('source_code_server/server.py', LOGIN_APP_DIR)
copy('source_code_server/users.db', LOGIN_APP_DIR) copy('source_code_server/users.db', LOGIN_APP_DIR)
def read(self, data_json): def read(self, data):
data_json['data'] = { data['filename'] = self.filemanager.filename
'filename': self.filemanager.filename, data['content'] = self.filemanager.file_contents
'content': self.filemanager.file_contents, data['language'] = self.filemanager.language
'language': self.filemanager.language, data['files'] = self.filemanager.files
'files': self.filemanager.files return data
}
def write(self, data_json): def write(self, data):
self.filemanager.file_contents = data_json['data']['content'] self.filemanager.file_contents = data['content']
data_json['data']['files'] = self.filemanager.files data['files'] = self.filemanager.files
self.restart_process() self.restart_process()
return data
def select(self, data_json): def select(self, data):
try: try: self.filemanager.select_file(data['filename'])
self.filemanager.select_file(data_json['data']['filename']) except EnvironmentError: log.critical('Failed to select file "{}"'.format(data['filename']))
except EnvironmentError: return data
log.critical('Failed to select file "{}"'.format(data_json['data']['filename']))
def handle_event(self, anchor, data_json): def handle_event(self, anchor, data_json):
data = data_json['data'] data = data_json['data']
self.commands[data['command']](data_json) data_json['data'] = self.commands[data['command']](data)
return data_json return data_json