From b6aa4602c25b9a7529e04ba4be531a0343f7d059 Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Fri, 20 Dec 2013 09:34:46 +1100 Subject: [PATCH] profile: add a rule for temporary over-rides. A rule "<10" will succeed for the 10 minutes following the modify time of the file containing the rule. --- lib/profile.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/profile.py b/lib/profile.py index 6c40676..c8a1708 100644 --- a/lib/profile.py +++ b/lib/profile.py @@ -37,15 +37,17 @@ def load_profile(p, t): read_profile(p, "/data/profiles/"+t) def load_rules(file, p, event, who): + when = 0 try: f = open(file) l = f.readlines() + when = os.fstat(f.fileno()).st_mtime except IOError: l = [] for ln in l: ln = ln.strip() w = ln.split(':', 1) - if len(w) == 2 and rule_matches(w[0].strip(), event, who): + if len(w) == 2 and rule_matches(w[0].strip(), event, who, when): load_profile(p, w[1].strip()) def get_profile(event, who): @@ -63,11 +65,13 @@ def get_profile(event, who): pass return p -def rule_matches(rule, event, who): +def rule_matches(rule, event, who, when): if rule == '': return True if rule == event: return True + if rule[0] == '<' and rule[1:].isdigit(): + return time.time() >= when and time.time() < when + int(rule[1:])*60 for w in who.split(' '): if w[-8:] == rule[-8:]: return True -- 2.39.5