X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmanagers%2Fmanagerwrapper.py;h=58a0527b422b33262088528367ebfc10549859d3;hb=b6de9285a970eccb9658a0078c49f76fb11af7cd;hp=5231c2aa320b943dac6d88f68eebb9b2f9e0b96e;hpb=e6c8a0a5061bae7e646851b6f265a02cdfb57f22;p=sfa.git diff --git a/sfa/managers/managerwrapper.py b/sfa/managers/managerwrapper.py index 5231c2aa..58a0527b 100644 --- a/sfa/managers/managerwrapper.py +++ b/sfa/managers/managerwrapper.py @@ -1,4 +1,6 @@ -from sfa.util.faults import SfaNotImplemented +from types import ModuleType, ClassType + +from sfa.util.faults import SfaNotImplemented, SfaAPIError from sfa.util.sfalogging import logger #################### @@ -13,12 +15,20 @@ class ManagerWrapper: is not implemented by a libarary and will generally be more helpful than the standard AttributeError """ - def __init__(self, manager, interface): - self.manager = manager + def __init__(self, manager, interface, config): + if isinstance (manager, ModuleType): + # old-fashioned module implementation + self.manager = manager + elif isinstance (manager, ClassType): + # create an instance; we don't pass the api in argument as it is passed + # to the actual method calls anyway + self.manager = manager(config) + else: + raise SfaAPIError,"Argument to ManagerWrapper must be a module or class" self.interface = interface def __getattr__(self, method): if not hasattr(self.manager, method): - raise SfaNotImplemented(method, self.interface) + raise SfaNotImplemented(self.interface, method) return getattr(self.manager, method)