From: NeilBrown Date: Thu, 19 Dec 2013 22:34:46 +0000 (+1100) Subject: profile: add a rule for temporary over-rides. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=b6aa4602c25b9a7529e04ba4be531a0343f7d059;p=plato.git 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. --- 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