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
+ - <N: rule file was changed less than N minutes ago
+ - day-of-week: mo,we,fr-su
+ - time-of-day: 10.00-11.30,23.30-01.30
+ """
+ for r in rule.split(' '):
+ if r == '':
+ continue
+ if r == event:
+ continue
+ if len(r) > 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!!!