scripts/gestion/trigger/host.py
2014-06-15 00:31:21 +02:00

32 lines
795 B
Python

#!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*-
#
# Basic trigger host, will be imported from any other
# Contains a TriggerFactory, which records the host functions
# decorated with @record.
# Contains a trigger which calls good functions from factory.
#
# Author : Pierre-Elliott Bécue <becue@crans.org>
# License : GPLv3
# Date : 28/04/2014
class TriggerFactory(object):
"""Factory containing which function is part of the trigger set
"""
_meths = {}
@classmethod
def register(cls, key, value):
cls._meths[key] = value
@classmethod
def get(cls, key):
return cls._meths.get(key, None)
def record(function):
TriggerFactory.register(function.func_name, function)
def trigger(what):
return TriggerFactory.get(what)