1 from sfa.util.faults import SfaNotImplemented
2 from sfa.util.sfalogging import logger
4 ## locate the right manager
5 def import_manager(kind, type):
7 kind expected in ['registry', 'aggregate', 'slice', 'component']
8 type is e.g. 'pl' or 'max' or whatever
10 basepath = 'sfa.managers'
11 qualified = "%s.%s_manager_%s"%(basepath,kind,type)
12 generic = "%s.%s_manager"%(basepath,kind)
14 message="import_manager for kind=%s and type=%s"%(kind,type)
16 manager = __import__(qualified, fromlist=[basepath])
17 logger.info ("%s: loaded %s"%(message,qualified))
20 manager = __import__ (generic, fromlist=[basepath])
22 logger.warn ("%s: using generic with type!='pl'"%(message))
23 logger.info("%s: loaded %s"%(message,generic))
26 logger.log_exc("%s: unable to import either %s or %s"%(message,qualified,generic))
32 This class acts as a wrapper around an SFA interface manager module, but
33 can be used with any python module. The purpose of this class is raise a
34 SfaNotImplemented exception if someone attempts to use an attribute
35 (could be a callable) thats not available in the library by checking the
36 library using hasattr. This helps to communicate better errors messages
37 to the users and developers in the event that a specifiec operation
38 is not implemented by a libarary and will generally be more helpful than
39 the standard AttributeError
41 def __init__(self, manager, interface):
42 self.manager = manager
43 self.interface = interface
45 def __getattr__(self, method):
46 if not hasattr(self.manager, method):
47 raise SfaNotImplemented(method, self.interface)
48 return getattr(self.manager, method)