Fix pep8 support in src/tools.

This commit is contained in:
Emmanuel Gil Peyrot 2013-01-18 17:55:35 +01:00
commit fb0d7c9ca4

View file

@ -19,34 +19,38 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from logging import debug, info, error
"""Misc usefull classes"""
class TriggerException(Exception):
pass
class SkipOtherTriggers(Exception):
""" Exception to raise if normal behaviour must be followed instead of
followind triggers list """
pass
class TriggerManager(object):
"""This class manage triggers: code which interact to change de behaviour of SàT"""
"""This class manage triggers: code which interact to change de behaviour
of SàT"""
def __init__(self):
self.__triggers={}
self.__triggers = {}
def add(self, point_name, callback, priority=0):
"""Add a trigger to a point
@param point_name: name of the point when the trigger should be run
@param callback: method to call at the trigger point
@param priority: callback will be called in priority order, biggest first
@param priority: callback will be called in priority order, biggest
first
"""
if not self.__triggers.has_key(point_name):
self.__triggers[point_name]=[]
if point_name not in self.__triggers:
self.__triggers[point_name] = []
self.__triggers[point_name].append((priority, callback))
self.__triggers[point_name].sort(key=lambda trigger_tuple: trigger_tuple[0], reverse=True)
self.__triggers[point_name].sort(key=lambda trigger_tuple:
trigger_tuple[0], reverse=True)
def remove(self, point_name, callback):
"""Remove a trigger from a point
@ -63,7 +67,7 @@ class TriggerManager(object):
All the trigger for that point will be run
@param point_name: name of the trigger point
@return: True if the action must be continued, False else"""
if not self.__triggers.has_key(point_name):
if point_name not in self.__triggers:
return True
for priority,trigger in self.__triggers[point_name]:
@ -73,4 +77,3 @@ class TriggerManager(object):
except SkipOtherTriggers:
break
return True