mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-05 16:31:21 +00:00
Refactor YamlFSM moar
This commit is contained in:
parent
bfa1bffbc5
commit
ea76a19595
@ -10,7 +10,7 @@ from tfw import FSMBase
|
||||
class YamlFSM(FSMBase):
|
||||
def __init__(self, config_file):
|
||||
self.config = self.parse_config(config_file)
|
||||
self.patch_config_callbacks()
|
||||
self.for_config_states_and_transitions_do(self.patch_config_callbacks)
|
||||
self.setup_states()
|
||||
super().__init__() # FSMBase.__init__() requires states
|
||||
self.setup_transitions()
|
||||
@ -27,14 +27,16 @@ class YamlFSM(FSMBase):
|
||||
for transition in self.config['transitions']:
|
||||
self.add_transition(**transition)
|
||||
|
||||
def patch_config_callbacks(self):
|
||||
topatch = ('on_enter', 'on_exit', 'prepare', 'before', 'after')
|
||||
|
||||
def for_config_states_and_transitions_do(self, what):
|
||||
for array in ('states', 'transitions'):
|
||||
for json_obj in self.config[array]:
|
||||
for key in json_obj:
|
||||
if key in topatch:
|
||||
json_obj[key] = partial(self.run, json_obj[key])
|
||||
what(json_obj)
|
||||
|
||||
def patch_config_callbacks(self, json_obj):
|
||||
topatch = ('on_enter', 'on_exit', 'prepare', 'before', 'after')
|
||||
for key in json_obj:
|
||||
if key in topatch:
|
||||
json_obj[key] = partial(self.run, json_obj[key])
|
||||
|
||||
@staticmethod
|
||||
def run(command, event):
|
||||
|
Loading…
Reference in New Issue
Block a user