def __init__(self, filename): cls = TestableComponent # If we recieve a filename like 'iaf', that doesn't # end in '.py', then lets prepend the component directory # and append .py if not filename.endswith('.py'): compdir = LocationMgr.getComponentDir() filename = os.path.join(compdir, '%s.py' % filename) self.filename = filename self.mod = load_py_module(filename) # Get the component functor: if not cls.functor_name in self.mod.__dict__.keys(): err = """Can't load TestableComponnet from %s""" % self.filename err += """Can't find required method: %s""" % cls.functor_name raise NineMLRuntimeError(err) self.component_functor = self.mod.__dict__[cls.functor_name] # Check the functor will actually return us an object: try: c = self.component_functor() except Exception, e: print e raise
def list_available(cls): """Returns a list of strings, of the available components""" compdir = LocationMgr.getComponentDir() comps = [] for fname in os.listdir(compdir): fname, ext = os.path.splitext(fname) if not ext == '.py': continue if fname == '__init__': continue comps.append(fname) return comps