From 3d428adc124cf508cf1d0119fa56ba65639cc3c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Wed, 30 Apr 2014 21:38:48 +0200 Subject: [PATCH] =?UTF-8?q?[trigger/host.py]=20Fichier=20d'h=C3=B4te=20g?= =?UTF-8?q?=C3=A9n=C3=A9rique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gestion/trigger/host.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 gestion/trigger/host.py 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)