core (tools): set min and max priorities for triggers and warn if several triggers have the same not null priority

This commit is contained in:
souliane 2013-12-13 05:35:24 +01:00
commit b674011891

View file

@ -19,6 +19,8 @@
"""Misc usefull classes"""
import sys
from logging import debug, warning
class TriggerException(Exception):
pass
@ -34,6 +36,9 @@ class TriggerManager(object):
"""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 @@ class TriggerManager(object):
"""
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)