36 lines
867 B
Python
36 lines
867 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)
|
|
|
|
@classmethod
|
|
def get_services(cls):
|
|
return cls._meths.values()
|
|
|
|
def record(cls):
|
|
TriggerFactory.register(cls.__name__.lower(), cls)
|
|
|
|
def trigger(what):
|
|
return TriggerFactory.get(what)
|