From: NeilBrown Date: Thu, 19 Dec 2013 22:46:33 +0000 (+1100) Subject: profile: multiple conditions in a rule. X-Git-Url: http://git.neil.brown.name/?a=commitdiff_plain;h=7089fe4f2a702552f8e787a24420d9b75fe93d5b;p=plato.git profile: multiple conditions in a rule. A rule can have multiple conditions. All must succeed. --- diff --git a/lib/profile.py b/lib/profile.py index c8a1708..42780fe 100644 --- a/lib/profile.py +++ b/lib/profile.py @@ -66,26 +66,40 @@ def get_profile(event, who): return p 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 - dt = rule.split(' ') - tm = time.localtime() - for d in dt: - a = day_match(d, tm) - if a == None: - a = time_match(d, tm) + """A rule can contain several words. If none fail, + the rule succeeds (so an empty rule always succeeds) + words can match: + - The event: ring sms alarm + - who: last 8 digits must match, "who" can be a list + - 1 and r[0] == '<' and r[1:].isdigit(): + if time.time() >= when and time.time() < when + int(r[1:])*60: + continue + return False + + for w in who.split(' '): + if w[-8:] == r[-8:]: + continue + + tm = time.localtime() + a = day_match(r, tm) + if a == False: + return False if a == True: - return True - #if a == None: - # raise ValueError - return False + continue + a = time_match(r, tm) + if a == False: + return False + + return True # python is broken: tm_wday==0 means monday!!!