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:
parent
5c39b346a8
commit
b674011891
1 changed files with 10 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue