From d73780cacd8c008093ce29af0b561b665818b2bf Mon Sep 17 00:00:00 2001 From: Yves G Date: Wed, 31 Jan 2018 11:58:12 +0100 Subject: [PATCH] "then" is now applicable to filters as well as actions --- pyruse/module.py | 5 ++--- pyruse/workflow.py | 16 +++++++--------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pyruse/module.py b/pyruse/module.py index 0dc69d6..2871b8a 100644 --- a/pyruse/module.py +++ b/pyruse/module.py @@ -1,5 +1,5 @@ # pyruse is intended as a replacement to both fail2ban and epylog -# Copyright © 2017 Y. Gablin +# Copyright © 2017–2018 Y. Gablin # Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing. import importlib from pyruse import log @@ -19,16 +19,15 @@ def get(moduleDesc): isAction = False mod = _getModule("pyruse.filters." + moduleDesc["filter"]) obj = mod.Filter(moduleDesc.get("args", {})) - thenRun = None elseRun = moduleDesc["else"] if "else" in moduleDesc else None elif "action" in moduleDesc: isAction = True mod = _getModule("pyruse.actions." + moduleDesc["action"]) obj = mod.Action(moduleDesc.get("args", {})) - thenRun = moduleDesc["then"] if "then" in moduleDesc else None elseRun = None else: raise ValueError("Step is neither “filter” nor “action”: %s\n" % str(moduleDesc)) + thenRun = moduleDesc["then"] if "then" in moduleDesc else None return Module(isAction, obj, thenRun, elseRun) def _getModule(modName): diff --git a/pyruse/workflow.py b/pyruse/workflow.py index 5798796..b99f3b9 100644 --- a/pyruse/workflow.py +++ b/pyruse/workflow.py @@ -1,5 +1,5 @@ # pyruse is intended as a replacement to both fail2ban and epylog -# Copyright © 2017 Y. Gablin +# Copyright © 2017–2018 Y. Gablin # Full licensing information in the LICENSE file, or gnu.org/licences/gpl-3.0.txt if the file is missing. from pyruse import log, module @@ -33,19 +33,17 @@ class Workflow: break mod = module.get(step) obj = mod.module - if mod.isAction: - if mod.thenRun: - (seen, dangling) = \ - self._branchToChain(obj.setNextStep, mod.thenRun, actions, seen, dangling) - isThenCalled = True - isPreviousDangling = False - else: + if mod.thenRun: + (seen, dangling) = \ + self._branchToChain(obj.setNextStep, mod.thenRun, actions, seen, dangling) + isThenCalled = True + if mod.isFilter: if mod.elseRun: (seen, dangling) = \ self._branchToChain(obj.setAltStep, mod.elseRun, actions, seen, dangling) else: dangling.append(obj.setAltStep) - isPreviousDangling = True + isPreviousDangling = mod.isFilter and not isThenCalled if previousSetter: previousSetter(obj) else: