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
Example #2
0
    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 = modname + ".dbg"
        # self.tabmodule = modname + "_" + "parsetab"

        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
from nineml.utility import LocationMgr
from os.path import join as Join
from nineml.abstraction_layer.xmlns import *

import nineml.abstraction_layer as al
import nineml.abstraction_layer.readers as readers
import nineml.abstraction_layer.writers as writers

import pyNN.neuron.nineml as pyNNml

from nineml.abstraction_layer.flattening import ComponentFlattener

#LocationMgr.StdAppendToPath()


sample_xml_dir = Join(LocationMgr.getCatalogDir(), "sample_xml_files")
tenml_dir = Join(LocationMgr.getCatalogDir(), "sample_xml_files/10ml/")


def t1():
    print 'Loading First XML File'
    print '----------------------'
    component = readers.XMLReader.read_component(Join(sample_xml_dir, 'PostTF_izhikevich.xml'))
    writers.XMLWriter.write(component, '/tmp/nineml_toxml1.xml')


def t2():
    print 'Loading Second XML File (IAF-Component'
    print '--------------------------------------'
    component = readers.XMLReader.read_component(Join(tenml_dir, 'comp_iaf.9ml'))
    writers.XMLWriter.write(component, '/tmp/nineml_toxml2.xml')