mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 11:32:55 +00:00 
			
		
		
		
	Add first version of YamlFSM
This commit is contained in:
		@@ -4,3 +4,4 @@
 | 
			
		||||
from .event_handler_base import EventHandlerBase, TriggeredEventHandler, BroadcastingEventHandler
 | 
			
		||||
from .fsm_base import FSMBase
 | 
			
		||||
from .linear_fsm import LinearFSM
 | 
			
		||||
from .yaml_fsm import YamlFSM
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										18
									
								
								lib/tfw/yaml_fsm.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								lib/tfw/yaml_fsm.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,18 @@
 | 
			
		||||
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)
 | 
			
		||||
@@ -3,3 +3,4 @@ pyzmq==17.0.0
 | 
			
		||||
transitions==0.6.4
 | 
			
		||||
terminado==0.8.1
 | 
			
		||||
watchdog==0.8.3
 | 
			
		||||
PyYAML==3.12
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user