diff --git a/gestion/trigger/host.py b/gestion/trigger/host.py new file mode 100644 index 00000000..fd365c7b --- /dev/null +++ b/gestion/trigger/host.py @@ -0,0 +1,33 @@ +#!/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 function which should be imported as its with +# record, to be used in hosts contained in hosts/ directory. +# +# Author : Pierre-Elliott Bécue +# 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)