]> git.neil.brown.name Git - plato.git/commitdiff
profile: add a rule for temporary over-rides.
authorNeilBrown <neilb@suse.de>
Thu, 19 Dec 2013 22:34:46 +0000 (09:34 +1100)
committerNeilBrown <neilb@suse.de>
Thu, 19 Dec 2013 22:45:31 +0000 (09:45 +1100)
A rule "<10" will succeed for the 10 minutes following the modify
time of the file containing the rule.

lib/profile.py

index 6c4067696545844992fe369c2e41f9de2e80bc0b..c8a1708c71c321ac714b0f1fea188f7cd5635835 100644 (file)
@@ -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