Commit 6d27242f authored by kaiyou's avatar kaiyou

Make the recurrence hook more generic

parent ab37c9e1
...@@ -18,20 +18,25 @@ def populate(context, args, key, table): ...@@ -18,20 +18,25 @@ def populate(context, args, key, table):
return (context, args) return (context, args)
def postcheck(context, result): def recurrence(context, result, fields=["up"], dest="stable", dest_prev=None):
""" Basic post-check hooks """ Compute the recurrence of a the value of given fields
""" """
return merge_result(*recurrence(context, result)) recur = {}
prev = {}
if dest in context:
def recurrence(context, result, field="recurrence", reference=["up"]): fields = fields + list(context[dest])
""" Compute the recurrence of a check state in a field if type(context[dest]) is dict:
""" recur.update(context[dest])
recurring = all( for field in fields:
context.get(key, None) is result.get(key, None) recur[field] = (
for key in reference recur.get(field, 0) + 1
) if context.get(field, None) == result.get(field, -1)
context[field] = (context.get(field, 0) + 1) if recurring else 0 else 0
)
prev[field] = context.get(field, None)
context[dest] = recur
if prev is not None:
context[dest_prev] = prev
return context, result return context, result
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment