Beispiel #1
0
def load_module(agent, modname):
    chron = time.time()
    succeeds = 1
    try:
        # PERSIST:INSTRUMENT
        report_instrumentation_point(agent, PRE_USER_MODULE_LOAD)
        mod = ensure_modpath_installed(Symbol(modname))
        if not mod:
            print "=== COULD NOT INSTALL MODULE %s ===" % modname
            succeeds = 0
        currMod = get_default_module()
        # check for equality here because we are reporting instrumentation points
        if mod is not currMod:
            set_default_module(mod)
            if not ensure_default_module_loaded(agent):
                print "=== COULD NOT LOAD MODULE %s ===" % modname
                succeeds = 0
            # PERSIST:INSTRUMENT
            report_instrumentation_point(agent, POST_USER_MODULE_LOAD)
    except SPARKException:
        errid = NEWPM.displayError()
    chron = time.time() - chron
    print "Total Loading Time: %3.4f seconds." % chron
    # -*-*-*-*-*-* This is a hack to remove the logs from the console. A better solution is needed later.
    from spark.util.logger import get_sdl

    get_sdl().log("Default Module: %s", modname)
    return succeeds
Beispiel #2
0
def execute_spark_main(agent, module_args):
    """module_args must be in an evaluable/string representation"""
    mod = get_default_module()
    if mod is None:
        print "WARNING - NO DEFAULT MODULE SO MAIN IS NOT BEING RUN"
        return None
    from spark.internal.parse.processing import OK4

    if not mod.atLeast(OK4):
        # TODO: Clean this up - it is ugly
        from spark.internal.parse.processing import FILENAME_SPU

        FILENAME_SPU.get4(mod.filename)
        if not mod.atLeast(OK4):
            print "WARNING - MODULE NOT OK4 AND SO MAIN IS NOT BEING RUN", mod
            return None
    main = mod.main_name
    if main is None:
        return None
    try:
        ext = agent.run("[do: (%s [%s])]" % (main, " ".join(module_args)), get_modname())
        x = ext.wait_result()
    except Failure, e:
        print "The main action of file %s failed" % mod.filename
        return e
Beispiel #3
0
def get_modname():
    """helper function to hide the internal workings of the shifting module API"""
    mod = get_default_module()
    if mod is None:
        return "spark.lang.builtin"
    else:
        return mod.get_modpath().name
Beispiel #4
0
def _collect_symbols(agent, usage, collectAll):
    # ensure_default_module_loaded(agent)
    if collectAll:
        syms = agent.getDeclaredSymbols()
        decls = [agent.getDecl(n) for n in syms]
        names = [decl.asSymbol() for decl in decls if decl is not None and decl.optMode(usage)]
    else:
        mod = get_default_module()
        if mod is None:
            raise LowError("Default module is not loaded")
        decls = getPackageDecls(agent, mod.filename)
        names = [decl.asSymbol() for decl in decls if decl is not None and decl.optMode(usage)]
    return names
Beispiel #5
0
def run_cmd(agent, cmd):
    mod = get_default_module()
    if mod is None:
        return "Module %s not found"%mod.filename
    main = mod.main_name
    if main is None:
        return "Module %s main not found"%mod.filename
    try:
        ext = agent.run(cmd, get_modname())
        x = ext.wait_result()
    except Exception, e:
        print "Test in %s failed to execute"%mod.filename
        return e
Beispiel #6
0
def persist_default_module():
    from spark.internal.parse.processing import get_default_module
    #print "persist_default_module"
    #Testing Script. Begin:
#    global chronometers
#    chronometers["persistence_default_module"].start()
    #Testing Script. End.
    dm = get_default_module()
    if not dm:
        #Testing Script. Begin:
#        chronometers["persistence_default_module"].stop()
        #Testing Script. End.
        return #no default module, happens during loading
    f = open(os.path.join(get_persist_root_dir(), "defaultModule"), 'w')
    f.write(dm.get_modpath().name)
    f.close()