def _load_backend(_backend, _platform): """load a process backend""" name = None _has_all = False try: name = __name__ + '.' + _platform mod = __import__(name, {}, {}, [_platform]) #validate the module interface if not IKittProcModule.providedBy(mod): e = ImportError("%s does not implement IKittProcModule interface" \ % name) raise e #throw exception as an import error if '__all__' in vars(mod): _EXPORTED.update(set(mod.__all__)) _has_all = True for var, obj in vars(mod).items(): if hasattr(obj, '__class__') and var in _process_interfaces: #demonstrate you at least read the implementation if not _process_interfaces[var].implementedBy(obj): e = 'Class [%s] from %s does not match interface' % \ (var,name) warnings.warn(e) continue #update our namespace globals().update({var: obj}) if _has_all: continue #add to exported interfaces if not var.startswith('_'): _EXPORTED.add(var) except ImportError: raise except AssertionError: pass except: traceback.print_exc()
_platform = platform.system() _backend = os.path.join(os.path.abspath(os.path.dirname(__file__)), _platform + '.py' ) #exportable interfaces _EXPORTED = set(_process_interfaces.keys() + _required_methods) if os.path.exists(_backend): name = None _has_all = False try: name = __name__ + '.' + _platform mod = __import__(name, {}, {}, [_platform]) mod.InvalidProcess = InvalidProcess #for compatibility #validate the module interface if not IKittProcModule.providedBy(mod): e = ImportError("%s does not implement IKittProcModule interface" \ % name) raise e #throw exception as an import error if '__all__' in vars(mod): _EXPORTED.update(set(mod.__all__)) _has_all = True for var, obj in vars(mod).items(): if hasattr(obj, '__class__') and var in _process_interfaces: #demonstrate you at least read the implementation if not _process_interfaces[var].implementedBy(obj): e = 'Class [%s] from %s does not match interface' % \ (var,name) warnings.warn(e) continue #update our namespace