[actions] support multiple actions per pattern

This commit is contained in:
Mike Fährmann
2024-06-30 02:06:09 +02:00
parent 8219a78b8d
commit f41a5065b2
2 changed files with 38 additions and 11 deletions

View File

@@ -27,9 +27,17 @@ def parse(actionspec):
for event, spec in actionspec:
level, _, pattern = event.partition(":")
type, _, args = spec.partition(" ")
search = re.compile(pattern).search if pattern else util.true
action = (search, ACTIONS[type](args))
if isinstance(spec, str):
type, _, args = spec.partition(" ")
action = (search, ACTIONS[type](args))
else:
action_list = []
for s in spec:
type, _, args = s.partition(" ")
action_list.append(ACTIONS[type](args))
action = (search, _chain_actions(action_list))
level = level.strip()
if not level or level == "*":
@@ -50,6 +58,13 @@ def _level_to_int(level):
return int(level)
def _chain_actions(actions):
def _chain(args):
for action in actions:
action(args)
return _chain
def action_print(opts):
def _print(_):
print(opts)