diff src/tools/misc.py @ 741:00318e60a06a

core (tools): set min and max priorities for triggers and warn if several triggers have the same not null priority
author souliane <souliane@mailoo.org>
date Fri, 13 Dec 2013 05:35:24 +0100
parents 84a6e83157c2
children 03744d9ebc13
line wrap: on
line diff
--- 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)