mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-09-09 00:04:10 +00:00
Remove controller stuff, tidy code based on pylint suggestions
This commit is contained in:
parent
7c13d31de0
commit
a79c68515b
@ -33,6 +33,7 @@ class FSMManagingEventHandler(EventHandlerBase):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
def handle_update(self, data):
|
def handle_update(self, data):
|
||||||
|
# pylint: disable=no-self-use
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
from os.path import isfile, join, relpath, exists, isdir, realpath
|
from os.path import isfile, join, relpath, exists, isdir, realpath
|
||||||
from glob import glob
|
from glob import glob
|
||||||
from fnmatch import fnmatchcase
|
from fnmatch import fnmatchcase
|
||||||
from collections import Iterable
|
from typing import Iterable
|
||||||
|
|
||||||
from tfw import EventHandlerBase
|
from tfw import EventHandlerBase
|
||||||
from tfw.mixins import MonitorManagerMixin
|
from tfw.mixins import MonitorManagerMixin
|
||||||
@ -103,7 +103,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
|
|||||||
|
|
||||||
|
|
||||||
class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
|
class IdeEventHandler(EventHandlerBase, MonitorManagerMixin):
|
||||||
# pylint: disable=too-many-arguments
|
# pylint: disable=too-many-arguments,anomalous-backslash-in-string
|
||||||
"""
|
"""
|
||||||
Event handler implementing the backend of our browser based IDE.
|
Event handler implementing the backend of our browser based IDE.
|
||||||
By default all files in the directory specified in __init__ are displayed
|
By default all files in the directory specified in __init__ are displayed
|
||||||
|
@ -11,6 +11,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class TerminalCommands(ABC):
|
class TerminalCommands(ABC):
|
||||||
|
# pylint: disable=anomalous-backslash-in-string
|
||||||
"""
|
"""
|
||||||
A class you can use to define hooks for terminal commands. This means that you can
|
A class you can use to define hooks for terminal commands. This means that you can
|
||||||
have python code executed when the user enters a specific command to the terminal on
|
have python code executed when the user enters a specific command to the terminal on
|
||||||
|
@ -120,7 +120,7 @@ class FSMAwareEventHandler(EventHandlerBase, ABC):
|
|||||||
def dispatch_handling(self, message):
|
def dispatch_handling(self, message):
|
||||||
if message['key'] == 'fsm_update':
|
if message['key'] == 'fsm_update':
|
||||||
self._handle_fsm_update(message)
|
self._handle_fsm_update(message)
|
||||||
else:
|
return None
|
||||||
return super().dispatch_handling(message)
|
return super().dispatch_handling(message)
|
||||||
|
|
||||||
def _handle_fsm_update(self, message):
|
def _handle_fsm_update(self, message):
|
||||||
|
@ -58,7 +58,6 @@ class FSMBase(Machine, CallbackMixin):
|
|||||||
for predicate in self.trigger_predicates[trigger]
|
for predicate in self.trigger_predicates[trigger]
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: think about what could we do when this prevents triggering
|
|
||||||
if all(predicate_results):
|
if all(predicate_results):
|
||||||
try:
|
try:
|
||||||
self.trigger(trigger)
|
self.trigger(trigger)
|
||||||
|
@ -9,6 +9,7 @@ from tfw.decorators import lazy_property
|
|||||||
class CallbackMixin:
|
class CallbackMixin:
|
||||||
@lazy_property
|
@lazy_property
|
||||||
def _callbacks(self):
|
def _callbacks(self):
|
||||||
|
# pylint: disable=no-self-use
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def subscribe_callback(self, callback, *args, **kwargs):
|
def subscribe_callback(self, callback, *args, **kwargs):
|
||||||
|
@ -9,6 +9,7 @@ from tfw.decorators import lazy_property
|
|||||||
class ObserverMixin:
|
class ObserverMixin:
|
||||||
@lazy_property
|
@lazy_property
|
||||||
def observer(self):
|
def observer(self):
|
||||||
|
# pylint: disable=no-self-use
|
||||||
return Observer()
|
return Observer()
|
||||||
|
|
||||||
def watch(self):
|
def watch(self):
|
||||||
|
@ -13,6 +13,7 @@ from tfw.config import TFWENV
|
|||||||
class SupervisorBaseMixin:
|
class SupervisorBaseMixin:
|
||||||
@lazy_property
|
@lazy_property
|
||||||
def supervisor(self):
|
def supervisor(self):
|
||||||
|
# pylint: disable=no-self-use
|
||||||
return xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
|
return xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,18 +0,0 @@
|
|||||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
||||||
# All Rights Reserved. See LICENSE file for details.
|
|
||||||
|
|
||||||
import zmq
|
|
||||||
from zmq.eventloop.zmqstream import ZMQStream
|
|
||||||
|
|
||||||
from tfw.config import TFWENV
|
|
||||||
from tfw.networking import ZMQConnectorBase
|
|
||||||
|
|
||||||
|
|
||||||
class ControllerConnector(ZMQConnectorBase):
|
|
||||||
def __init__(self, zmq_context=None):
|
|
||||||
super(ControllerConnector, self).__init__(zmq_context)
|
|
||||||
self._zmq_rep_socket = self._zmq_context.socket(zmq.REP)
|
|
||||||
self._zmq_rep_socket.connect(f'tcp://localhost:{TFWENV.CONTROLLER_PORT}')
|
|
||||||
self._zmq_rep_stream = ZMQStream(self._zmq_rep_socket)
|
|
||||||
|
|
||||||
self.register_callback = self._zmq_rep_stream.on_recv_stream
|
|
@ -3,4 +3,3 @@
|
|||||||
|
|
||||||
from .event_handler_connector import EventHandlerConnector, EventHandlerUplinkConnector, EventHandlerDownlinkConnector
|
from .event_handler_connector import EventHandlerConnector, EventHandlerUplinkConnector, EventHandlerDownlinkConnector
|
||||||
from .tfw_server import TFWServer
|
from .tfw_server import TFWServer
|
||||||
# from .controller_responder import ControllerResponder # TODO: readd once controller stuff is resolved
|
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
|
|
||||||
# All Rights Reserved. See LICENSE file for details.
|
|
||||||
|
|
||||||
from tfw.networking import deserialize_all, serialize_all, ControllerConnector
|
|
||||||
|
|
||||||
|
|
||||||
class ControllerResponder:
|
|
||||||
def __init__(self, fsm):
|
|
||||||
self.fsm = fsm
|
|
||||||
self.token = None
|
|
||||||
self.controller_connector = ControllerConnector()
|
|
||||||
self.controller_connector.register_callback(self.handle_controller_request)
|
|
||||||
self.controller_request_handlers = {
|
|
||||||
'solution_check': self.handle_solution_check_request,
|
|
||||||
'test': self.handle_test_request,
|
|
||||||
'token': self.handle_token_request
|
|
||||||
}
|
|
||||||
|
|
||||||
def handle_controller_request(self, stream, msg_parts):
|
|
||||||
key, data = deserialize_all(*msg_parts)
|
|
||||||
response = self.controller_request_handlers[key](data)
|
|
||||||
stream.send_multipart(serialize_all(self.token, response))
|
|
||||||
|
|
||||||
def handle_test_request(self, data):
|
|
||||||
# pylint: disable=unused-argument,no-self-use
|
|
||||||
return 'OK'
|
|
||||||
|
|
||||||
def handle_token_request(self, data):
|
|
||||||
if self.token is None:
|
|
||||||
self.token = data
|
|
||||||
return {'token': self.token}
|
|
||||||
|
|
||||||
def handle_solution_check_request(self, data):
|
|
||||||
# pylint: disable=unused-argument
|
|
||||||
return {
|
|
||||||
'solved': self.fsm.is_solved(),
|
|
||||||
'message': 'solved' if self.fsm.is_solved() else 'not solved'
|
|
||||||
}
|
|
@ -29,8 +29,7 @@ class TFWServer:
|
|||||||
'event_handler_connector': self._event_handler_connector,
|
'event_handler_connector': self._event_handler_connector,
|
||||||
'message_handlers': [self.handle_trigger, self.handle_recover],
|
'message_handlers': [self.handle_trigger, self.handle_recover],
|
||||||
'frontend_message_handlers': [self.save_frontend_messages]
|
'frontend_message_handlers': [self.save_frontend_messages]
|
||||||
})]
|
})])
|
||||||
)
|
|
||||||
|
|
||||||
self._frontend_messages = FrontendMessageStorage()
|
self._frontend_messages = FrontendMessageStorage()
|
||||||
|
|
||||||
@ -68,7 +67,7 @@ class MessageStorage(ABC):
|
|||||||
def filter_message(self, message):
|
def filter_message(self, message):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def transform_message(self, message):
|
def transform_message(self, message): # pylint: disable=no-self-use
|
||||||
yield message
|
yield message
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ LOG = logging.getLogger(__name__)
|
|||||||
|
|
||||||
|
|
||||||
class ZMQWebSocketProxy(WebSocketHandler):
|
class ZMQWebSocketProxy(WebSocketHandler):
|
||||||
|
# pylint: disable=abstract-method
|
||||||
instances = set()
|
instances = set()
|
||||||
|
|
||||||
def initialize(self, **kwargs): # pylint: disable=arguments-differ
|
def initialize(self, **kwargs): # pylint: disable=arguments-differ
|
||||||
@ -83,6 +84,7 @@ class ZMQWebSocketProxy(WebSocketHandler):
|
|||||||
|
|
||||||
|
|
||||||
class TFWProxy:
|
class TFWProxy:
|
||||||
|
# pylint: disable=protected-access
|
||||||
def __init__(self, to_source, to_destination):
|
def __init__(self, to_source, to_destination):
|
||||||
self.to_source = to_source
|
self.to_source = to_source
|
||||||
self.to_destination = to_destination
|
self.to_destination = to_destination
|
||||||
|
@ -52,7 +52,7 @@ class YamlFSM(FSMBase):
|
|||||||
json_obj.pop('predicates')
|
json_obj.pop('predicates')
|
||||||
|
|
||||||
|
|
||||||
def run_command_async(command, event):
|
def run_command_async(command, _):
|
||||||
Popen(command, shell=True)
|
Popen(command, shell=True)
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +62,7 @@ def command_statuscode_is_zero(command):
|
|||||||
|
|
||||||
class ConfigParser:
|
class ConfigParser:
|
||||||
def __init__(self, config_file, jinja2_variables):
|
def __init__(self, config_file, jinja2_variables):
|
||||||
self.read_variables = singledispatch(self.read_variables)
|
self.read_variables = singledispatch(self._read_variables)
|
||||||
self.read_variables.register(dict, self._read_variables_dict)
|
self.read_variables.register(dict, self._read_variables_dict)
|
||||||
self.read_variables.register(str, self._read_variables_str)
|
self.read_variables.register(str, self._read_variables_str)
|
||||||
|
|
||||||
@ -82,16 +82,14 @@ class ConfigParser:
|
|||||||
return ifile.read()
|
return ifile.read()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def read_variables(variables):
|
def _read_variables(variables):
|
||||||
raise TypeError(f'Invalid variables type {type(variables)}')
|
raise TypeError(f'Invalid variables type {type(variables)}')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _read_variables_str(variables):
|
def _read_variables_str(variables):
|
||||||
if isinstance(variables, str):
|
|
||||||
with open(variables, 'r') as ifile:
|
with open(variables, 'r') as ifile:
|
||||||
return yaml.safe_load(ifile)
|
return yaml.safe_load(ifile)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _read_variables_dict(variables):
|
def _read_variables_dict(variables):
|
||||||
return variables
|
return variables
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user