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 cls.functor_name not 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: raise NineMLRuntimeError('component_functor() threw an exception') if not isinstance(c, DynamicsClass): raise NineMLRuntimeError('Functor does not return Component Class') # Try and get the meta-data self.metadata = None if cls.metadata_name in self.mod.__dict__.keys(): self.metadata = self.mod.__dict__[cls.metadata_name]
def __init__(self, **kw): self.debug = kw.get('debug', 0) self.names = {} try: modname = os.path.split(os.path.splitext(__file__) [0])[1] + "_" + self.__class__.__name__ except: modname = "parser" + "_" + self.__class__.__name__ self.debugfile = LocationMgr.getTmpDir() + modname + ".dbg" self.tabmodule = LocationMgr.getTmpDir() + modname + "_" + "parsetab" # print self.debugfile, self.tabmodule # Build the lexer and parser lex.lex(module=self, debug=self.debug) yacc.yacc(module=self, debug=self.debug, debugfile=self.debugfile, tabmodule=self.tabmodule)
def __init__(self, **kw): self.debug = kw.get('debug', 0) self.names = {} try: modname = os.path.split(os.path.splitext(__file__)[0])[ 1] + "_" + self.__class__.__name__ except: modname = "parser" + "_" + self.__class__.__name__ self.debugfile = LocationMgr.getTmpDir() + modname + ".dbg" self.tabmodule = LocationMgr.getTmpDir() + modname + "_" + "parsetab" # print self.debugfile, self.tabmodule # Build the lexer and parser lex.lex(module=self, debug=self.debug) yacc.yacc(module=self, debug=self.debug, debugfile=self.debugfile, tabmodule=self.tabmodule)
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