# HG changeset patch # User souliane # Date 1386909324 -3600 # Node ID 00318e60a06acbb5ccaea6bb2bdf8b9267a3ebc8 # Parent aebc8ba05129ddb9ba26ca71c2930f3b133a1249 core (tools): set min and max priorities for triggers and warn if several triggers have the same not null priority diff -r aebc8ba05129 -r 00318e60a06a src/tools/misc.py --- a/src/tools/misc.py Mon Nov 25 13:32:21 2013 +0100 +++ b/src/tools/misc.py Fri Dec 13 05:35:24 2013 +0100 @@ -19,6 +19,8 @@ """Misc usefull classes""" +import sys +from logging import debug, warning class TriggerException(Exception): pass @@ -34,6 +36,9 @@ """This class manage triggers: code which interact to change de behaviour of SàT""" + MIN_PRIORITY = float('-inf') + MAX_PRIORITY = float('+inf') + def __init__(self): self.__triggers = {} @@ -46,6 +51,11 @@ """ if point_name not in self.__triggers: self.__triggers[point_name] = [] + if priority != 0 and priority in [trigger_tuple[0] for trigger_tuple in self.__triggers[point_name]]: + if priority in (MIN_PRIORITY, MAX_PRIORITY): + warning(_("There is already a bound priority [%s]") % point_name) + else: + debug(_("There is already a trigger with the same priority [%s]") % point_name) self.__triggers[point_name].append((priority, callback)) self.__triggers[point_name].sort(key=lambda trigger_tuple: trigger_tuple[0], reverse=True)