X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fmanagers%2Fmanagerwrapper.py;h=77af9bf6fdc89b436b3d84ac0b43f3781235b0e7;hb=7eb34251548a271ae964b2f7d7e0fad7a1e41f5a;hp=5231c2aa320b943dac6d88f68eebb9b2f9e0b96e;hpb=e39e728991b762ae0b52b52b06655f0c7f1b7421;p=sfa.git diff --git a/sfa/managers/managerwrapper.py b/sfa/managers/managerwrapper.py index 5231c2aa..77af9bf6 100644 --- a/sfa/managers/managerwrapper.py +++ b/sfa/managers/managerwrapper.py @@ -1,7 +1,11 @@ -from sfa.util.faults import SfaNotImplemented +from types import ModuleType, ClassType + +from sfa.util.faults import SfaNotImplemented, SfaAPIError from sfa.util.sfalogging import logger #################### + + class ManagerWrapper: """ This class acts as a wrapper around an SFA interface manager module, but @@ -13,12 +17,25 @@ 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: + # that's what happens when there's something wrong with the db + # or any bad stuff of that kind at startup time + logger.log_exc( + "Failed to create a manager, startup sequence is broken") + 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) -