mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-06 00:11:22 +00:00
19 lines
541 B
Python
19 lines
541 B
Python
import yaml
|
|
from transitions import State
|
|
|
|
from tfw import FSMBase
|
|
|
|
|
|
class YamlFSM(FSMBase):
|
|
def __init__(self, config_file):
|
|
self.config = self.parse_config(config_file)
|
|
self.states = [State(**state) for state in self.config['states']]
|
|
super(YamlFSM, self).__init__()
|
|
for transition in self.config['transitions']:
|
|
self.machine.add_transition(**transition)
|
|
|
|
@staticmethod
|
|
def parse_config(config_file):
|
|
with open(config_file, 'r') as ifile:
|
|
return yaml.load(ifile)
|