Mercurial > libervia-backend
comparison src/tools/misc.py @ 525:5431136501ab
core: Triggers can now frobid other triggers execution
if a trigger raise SkipOtherTriggers exception, normal behaviour will occure, skipping other triggers
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 21 Oct 2012 19:28:38 +0200 |
parents | 7ee15fbe8c08 |
children | ca13633d3b6b |
comparison
equal
deleted
inserted
replaced
524:0bb595eff25b | 525:5431136501ab |
---|---|
22 from logging import debug, info, error | 22 from logging import debug, info, error |
23 | 23 |
24 """Misc usefull classes""" | 24 """Misc usefull classes""" |
25 | 25 |
26 class TriggerException(Exception): | 26 class TriggerException(Exception): |
27 pass | |
28 | |
29 class SkipOtherTriggers(Exception): | |
30 """ Exception to raise if normal behaviour must be followed instead of | |
31 followind triggers list """ | |
27 pass | 32 pass |
28 | 33 |
29 class TriggerManager: | 34 class TriggerManager: |
30 """This class manage triggers: code which interact to change de behaviour of SàT""" | 35 """This class manage triggers: code which interact to change de behaviour of SàT""" |
31 | 36 |
60 @return: True if the action must be continued, False else""" | 65 @return: True if the action must be continued, False else""" |
61 if not self.__triggers.has_key(point_name): | 66 if not self.__triggers.has_key(point_name): |
62 return True | 67 return True |
63 | 68 |
64 for priority,trigger in self.__triggers[point_name]: | 69 for priority,trigger in self.__triggers[point_name]: |
65 if not trigger(*args, **kwargs): | 70 try: |
66 return False | 71 if not trigger(*args, **kwargs): |
72 return False | |
73 except SkipOtherTriggers: | |
74 break | |
67 return True | 75 return True |
68 | 76 |