mirror of
https://github.com/avatao-content/test-tutorial-framework
synced 2025-01-15 21:51:57 +00:00
Rename stuff in Command class to be more expressive
This commit is contained in:
parent
93f211c410
commit
b718f960f7
@ -17,45 +17,41 @@ def cenator(history):
|
|||||||
|
|
||||||
class Commands:
|
class Commands:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.command_impls = {self._parse_command_name(fun): getattr(self, fun) for fun in dir(self)
|
self._command_method_regex = r'^command_(.+)$'
|
||||||
if callable(getattr(self, fun))
|
self.command_implemetations = {self._parse_command_name(fun): getattr(self, fun) for fun in dir(self)
|
||||||
and self._is_command_implementation(fun)}
|
if callable(getattr(self, fun)) and self._is_command_implementation(fun)}
|
||||||
|
|
||||||
@staticmethod
|
def _is_command_implementation(self, method_name):
|
||||||
def _is_command_implementation(method_name):
|
return bool(self._match_command_regex(method_name))
|
||||||
return bool(Commands._match_command_regex(method_name))
|
|
||||||
|
|
||||||
@staticmethod
|
def _parse_command_name(self, method_name):
|
||||||
def _parse_command_name(method_name):
|
|
||||||
try:
|
try:
|
||||||
return Commands._match_command_regex(method_name).groups()[0]
|
return self._match_command_regex(method_name).groups()[0]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
@staticmethod
|
def _match_command_regex(self, string):
|
||||||
def _match_command_regex(string):
|
return match(self._command_method_regex, string)
|
||||||
command_impl_regex = r'^_command_impl_(.+)$'
|
|
||||||
return match(command_impl_regex, string)
|
|
||||||
|
|
||||||
def callback(self, history):
|
def callback(self, history):
|
||||||
parts = history[-1].split()
|
parts = history[-1].split()
|
||||||
command = parts[0]
|
command = parts[0]
|
||||||
if command in self.command_impls.keys():
|
if command in self.command_implemetations.keys():
|
||||||
try:
|
try:
|
||||||
self.command_impls[command](*parts[1:])
|
self.command_implemetations[command](*parts[1:])
|
||||||
except IndexError:
|
except IndexError:
|
||||||
LOG.debug('Command "%s" failed!', command)
|
LOG.debug('Command "%s" failed!', command)
|
||||||
|
|
||||||
def _command_impl_selectdir(self, *args):
|
def command_selectdir(self, *args):
|
||||||
TFWServerConnector().send_to_eventhandler('webide',
|
TFWServerConnector().send_to_eventhandler('webide',
|
||||||
{'data': {'command': 'selectdir',
|
{'data': {'command': 'selectdir',
|
||||||
'directory': args[0]}})
|
'directory': args[0]}})
|
||||||
|
|
||||||
def _command_impl_trigger(self, *args):
|
def command_trigger(self, *args):
|
||||||
TFWServerConnector().send('selectdir_needs_no_key',
|
TFWServerConnector().send('selectdir_needs_no_key',
|
||||||
{'trigger': args[0]})
|
{'trigger': args[0]})
|
||||||
|
|
||||||
def _command_impl_togglenext(self, *args):
|
def command_togglenext(self, *args):
|
||||||
if not hasattr(self, 'togglenext_visible'):
|
if not hasattr(self, 'togglenext_visible'):
|
||||||
self.togglenext_visible = True
|
self.togglenext_visible = True
|
||||||
TFWServerConnector().send('messagecontrol',
|
TFWServerConnector().send('messagecontrol',
|
||||||
|
Loading…
Reference in New Issue
Block a user