[trigger/host.py] Fichier d'hôte générique
This commit is contained in:
parent
c79599ba9d
commit
3d428adc12
1 changed files with 33 additions and 0 deletions
33
gestion/trigger/host.py
Normal file
33
gestion/trigger/host.py
Normal 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)
|
Loading…
Add table
Add a link
Reference in a new issue