mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-23 00:01:31 +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):
|
class YamlFSM(FSMBase):
|
||||||
def __init__(self, config_file):
|
def __init__(self, config_file):
|
||||||
self.config = self.parse_config(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()
|
self.setup_states()
|
||||||
super().__init__() # FSMBase.__init__() requires states
|
super().__init__() # FSMBase.__init__() requires states
|
||||||
self.setup_transitions()
|
self.setup_transitions()
|
||||||
@ -27,14 +27,16 @@ class YamlFSM(FSMBase):
|
|||||||
for transition in self.config['transitions']:
|
for transition in self.config['transitions']:
|
||||||
self.add_transition(**transition)
|
self.add_transition(**transition)
|
||||||
|
|
||||||
def patch_config_callbacks(self):
|
def for_config_states_and_transitions_do(self, what):
|
||||||
topatch = ('on_enter', 'on_exit', 'prepare', 'before', 'after')
|
|
||||||
|
|
||||||
for array in ('states', 'transitions'):
|
for array in ('states', 'transitions'):
|
||||||
for json_obj in self.config[array]:
|
for json_obj in self.config[array]:
|
||||||
for key in json_obj:
|
what(json_obj)
|
||||||
if key in topatch:
|
|
||||||
json_obj[key] = partial(self.run, json_obj[key])
|
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
|
@staticmethod
|
||||||
def run(command, event):
|
def run(command, event):
|
||||||
|
Loading…
Reference in New Issue
Block a user