baseimage-tutorial-framework/lib/tfw/yaml_fsm.py
2018-07-03 15:14:00 +02:00

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)