Remove controller stuff, tidy code based on pylint suggestions

This commit is contained in:
Kristóf Tóth 2018-07-16 11:17:06 +02:00
parent 7c13d31de0
commit a79c68515b
14 changed files with 27 additions and 81 deletions

View File

@ -33,6 +33,7 @@ class FSMManagingEventHandler(EventHandlerBase):
return data
def handle_update(self, data):
# pylint: disable=no-self-use
return data

View File

@ -4,7 +4,7 @@
from os.path import isfile, join, relpath, exists, isdir, realpath
from glob import glob
from fnmatch import fnmatchcase
from collections import Iterable
from typing import Iterable
from tfw import EventHandlerBase
from tfw.mixins import MonitorManagerMixin
@ -103,7 +103,7 @@ class FileManager: # pylint: disable=too-many-instance-attributes
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.
By default all files in the directory specified in __init__ are displayed

View File

@ -11,6 +11,7 @@ LOG = logging.getLogger(__name__)
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
have python code executed when the user enters a specific command to the terminal on

View File

@ -120,7 +120,7 @@ class FSMAwareEventHandler(EventHandlerBase, ABC):
def dispatch_handling(self, message):
if message['key'] == 'fsm_update':
self._handle_fsm_update(message)
else:
return None
return super().dispatch_handling(message)
def _handle_fsm_update(self, message):

View File

@ -58,7 +58,6 @@ class FSMBase(Machine, CallbackMixin):
for predicate in self.trigger_predicates[trigger]
)
# TODO: think about what could we do when this prevents triggering
if all(predicate_results):
try:
self.trigger(trigger)

View File

@ -9,6 +9,7 @@ from tfw.decorators import lazy_property
class CallbackMixin:
@lazy_property
def _callbacks(self):
# pylint: disable=no-self-use
return []
def subscribe_callback(self, callback, *args, **kwargs):

View File

@ -9,6 +9,7 @@ from tfw.decorators import lazy_property
class ObserverMixin:
@lazy_property
def observer(self):
# pylint: disable=no-self-use
return Observer()
def watch(self):

View File

@ -13,6 +13,7 @@ from tfw.config import TFWENV
class SupervisorBaseMixin:
@lazy_property
def supervisor(self):
# pylint: disable=no-self-use
return xmlrpc.client.ServerProxy(TFWENV.SUPERVISOR_HTTP_URI).supervisor

View File

@ -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

View File

@ -3,4 +3,3 @@
from .event_handler_connector import EventHandlerConnector, EventHandlerUplinkConnector, EventHandlerDownlinkConnector
from .tfw_server import TFWServer
# from .controller_responder import ControllerResponder # TODO: readd once controller stuff is resolved

View File

@ -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'
}

View File

@ -25,12 +25,11 @@ class TFWServer:
self._uplink_connector = ServerUplinkConnector()
self.application = Application([(
r'/ws', ZMQWebSocketProxy,{
r'/ws', ZMQWebSocketProxy, {
'event_handler_connector': self._event_handler_connector,
'message_handlers': [self.handle_trigger, self.handle_recover],
'frontend_message_handlers': [self.save_frontend_messages]
})]
)
})])
self._frontend_messages = FrontendMessageStorage()
@ -68,7 +67,7 @@ class MessageStorage(ABC):
def filter_message(self, message):
raise NotImplementedError
def transform_message(self, message):
def transform_message(self, message): # pylint: disable=no-self-use
yield message

View File

@ -12,6 +12,7 @@ LOG = logging.getLogger(__name__)
class ZMQWebSocketProxy(WebSocketHandler):
# pylint: disable=abstract-method
instances = set()
def initialize(self, **kwargs): # pylint: disable=arguments-differ
@ -83,6 +84,7 @@ class ZMQWebSocketProxy(WebSocketHandler):
class TFWProxy:
# pylint: disable=protected-access
def __init__(self, to_source, to_destination):
self.to_source = to_source
self.to_destination = to_destination

View File

@ -52,7 +52,7 @@ class YamlFSM(FSMBase):
json_obj.pop('predicates')
def run_command_async(command, event):
def run_command_async(command, _):
Popen(command, shell=True)
@ -62,7 +62,7 @@ def command_statuscode_is_zero(command):
class ConfigParser:
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(str, self._read_variables_str)
@ -82,16 +82,14 @@ class ConfigParser:
return ifile.read()
@staticmethod
def read_variables(variables):
def _read_variables(variables):
raise TypeError(f'Invalid variables type {type(variables)}')
@staticmethod
def _read_variables_str(variables):
if isinstance(variables, str):
with open(variables, 'r') as ifile:
return yaml.safe_load(ifile)
@staticmethod
def _read_variables_dict(variables):
return variables