baseimage-tutorial-framework/lib/tfw/yaml_fsm.py

19 lines
541 B
Python
Raw Normal View History

2018-07-03 13:14:00 +00:00
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)