comparison sat/tools/trigger.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 3a8e7ec4648a
comparison
equal deleted inserted replaced
2623:49533de4540b 2624:56f94936df1e
19 19
20 """Misc usefull classes""" 20 """Misc usefull classes"""
21 21
22 from sat.core.i18n import _ 22 from sat.core.i18n import _
23 from sat.core.log import getLogger 23 from sat.core.log import getLogger
24
24 log = getLogger(__name__) 25 log = getLogger(__name__)
25 26
26 27
27 class TriggerException(Exception): 28 class TriggerException(Exception):
28 pass 29 pass
29 30
30 31
31 class SkipOtherTriggers(Exception): 32 class SkipOtherTriggers(Exception):
32 """ Exception to raise if normal behaviour must be followed instead of following triggers list """ 33 """ Exception to raise if normal behaviour must be followed instead of following triggers list """
34
33 pass 35 pass
34 36
35 37
36 class TriggerManager(object): 38 class TriggerManager(object):
37 """This class manage triggers: code which interact to change the behaviour of SàT""" 39 """This class manage triggers: code which interact to change the behaviour of SàT"""
38 40
39 try: # FIXME: to be removed when a better solution is found 41 try: # FIXME: to be removed when a better solution is found
40 MIN_PRIORITY = float('-inf') 42 MIN_PRIORITY = float("-inf")
41 MAX_PRIORITY = float('+inf') 43 MAX_PRIORITY = float("+inf")
42 except: # XXX: Pyjamas will bug if you specify ValueError here 44 except: # XXX: Pyjamas will bug if you specify ValueError here
43 # Pyjamas uses the JS Float class 45 # Pyjamas uses the JS Float class
44 MIN_PRIORITY = Number.NEGATIVE_INFINITY 46 MIN_PRIORITY = Number.NEGATIVE_INFINITY
45 MAX_PRIORITY = Number.POSITIVE_INFINITY 47 MAX_PRIORITY = Number.POSITIVE_INFINITY
46 48
55 @param priority: callback will be called in priority order, biggest 57 @param priority: callback will be called in priority order, biggest
56 first 58 first
57 """ 59 """
58 if point_name not in self.__triggers: 60 if point_name not in self.__triggers:
59 self.__triggers[point_name] = [] 61 self.__triggers[point_name] = []
60 if priority != 0 and priority in [trigger_tuple[0] for trigger_tuple in self.__triggers[point_name]]: 62 if priority != 0 and priority in [
63 trigger_tuple[0] for trigger_tuple in self.__triggers[point_name]
64 ]:
61 if priority in (self.MIN_PRIORITY, self.MAX_PRIORITY): 65 if priority in (self.MIN_PRIORITY, self.MAX_PRIORITY):
62 log.warning(_(u"There is already a bound priority [%s]") % point_name) 66 log.warning(_(u"There is already a bound priority [%s]") % point_name)
63 else: 67 else:
64 log.debug(_(u"There is already a trigger with the same priority [%s]") % point_name) 68 log.debug(
69 _(u"There is already a trigger with the same priority [%s]")
70 % point_name
71 )
65 self.__triggers[point_name].append((priority, callback)) 72 self.__triggers[point_name].append((priority, callback))
66 self.__triggers[point_name].sort(key=lambda trigger_tuple: 73 self.__triggers[point_name].sort(
67 trigger_tuple[0], reverse=True) 74 key=lambda trigger_tuple: trigger_tuple[0], reverse=True
75 )
68 76
69 def remove(self, point_name, callback): 77 def remove(self, point_name, callback):
70 """Remove a trigger from a point 78 """Remove a trigger from a point
71 79
72 @param point_name: name of the point when the trigger should be run 80 @param point_name: name of the point when the trigger should be run