[trigger/host.py] Fichier d'hôte générique

This commit is contained in:
Pierre-Elliott Bécue 2014-04-30 21:38:48 +02:00
parent c79599ba9d
commit 3d428adc12

33
gestion/trigger/host.py Normal file
View file

@ -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 <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)