Remove subprocess spawning stuff from YamlFSM for SRP

This commit is contained in:
Kristóf Tóth 2018-07-04 18:15:34 +02:00
parent d71a25e30a
commit 1beb419b09

View File

@ -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):
def run_command_async(command, event):
Popen(command, shell=True)
@staticmethod
def statuscode_is_zero(command):
def command_statuscode_is_zero(command):
return run(command, shell=True).returncode == 0