From 1beb419b093b779f0e86ae128961a58316973dd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Wed, 4 Jul 2018 18:15:34 +0200 Subject: [PATCH] Remove subprocess spawning stuff from YamlFSM for SRP --- lib/tfw/yaml_fsm.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/tfw/yaml_fsm.py b/lib/tfw/yaml_fsm.py index 4b09d5c..d868a70 100644 --- a/lib/tfw/yaml_fsm.py +++ b/lib/tfw/yaml_fsm.py @@ -34,11 +34,12 @@ class YamlFSM(FSMBase): for json_obj in self.config[array]: what(json_obj) - def patch_config_callbacks(self, json_obj): + @staticmethod + def patch_config_callbacks(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]) + json_obj[key] = partial(run_command_async, json_obj[key]) def subscribe_and_remove_predicates(self, json_obj): for key in json_obj: @@ -47,17 +48,17 @@ class YamlFSM(FSMBase): self.subscribe_predicate( json_obj['trigger'], partial( - self.statuscode_is_zero, + command_statuscode_is_zero, predicate ) ) with suppress(KeyError): json_obj.pop('predicates') - @staticmethod - def run(command, event): - Popen(command, shell=True) - @staticmethod - def statuscode_is_zero(command): - return run(command, shell=True).returncode == 0 +def run_command_async(command, event): + Popen(command, shell=True) + + +def command_statuscode_is_zero(command): + return run(command, shell=True).returncode == 0