예제 #1
0
def rtmrun_with_tabs(packs, comps, cxts, delays, rates=None, ecxtpacks=None, host=None, port=None,terminal_options=""):
    pythonpath=commands.getoutput("which python")
    if os.environ.has_key("EUS"):
        if os.environ["EUS"] == "jskrbeusgl":
            euslisppath=commands.getoutput("which jskrbeusgl")
    else:
        euslisppath=commands.getoutput("which irteusgl")
    tmppaths=commands.getoutput("which -a invoke_command_with_sleep.sh").split('\n')
    invoke_commandpath=tmppaths[len(tmppaths)-1]

    tabcommands=[]
    rtcdcommands = []
    unames = []
    baseno = 2809

    if host == None:
        host = socket.gethostname()
    if port == None:
        port = 2809

    for (pack, comp, cxt, rte, delay) in zip(packs, comps, cxts, rates, delays):
        path=rtmpack(["find",pack])
        rtcdcommand = None
        if comp.find('.so')!=-1:
            cpos=comp.find(':')
            if cpos != -1:
                exec_context = comp[cpos+1:]
                comp = comp[:cpos]
            else:
                exec_context = None

            #use rtmgr for creating components
            uname = '_' + str(cxt)

            tmpfn = "/tmp/rtcconf" + uname + ".XXX"
            tmpconf = open(tmpfn, 'w')
            tmpconf.write("corba.nameservers: " + host + ":" + str(port) + "\n")
            tmpconf.write("logger.enable: NO\n")
            tmpconf.write("manager.instance_name: rtmext_manager" + uname + "\n")
            mmport = ordsum(uname) + baseno
            tmpconf.write("corba.master_manager:" + host + ":" + str(mmport) + "\n")
            tmpconf.write("manager.modules.load_path: ./\n")
            tmpconf.write("manager.modules.abs_path_allowed: yes\n")
            if rte == None:
                rte = 1000
            tmpconf.write("exec_cxt.periodic.rate: " + str(rte) + "\n")
            if exec_context!=None:
                tmpconf.write("exec_cxt.periodic.type: " + str(exec_context) + "\n")                
            tmpconf.close()
            rtcdcommand = "rtcd rtmextmgr -f " + tmpfn + " -d"
        
            tabcommands.append("--tab -t " + cxt + " -e \"" + rtcdcommand + "\"" + " --working-directory=" + path)
            unames.append(uname)
        else:
            comppath = search_file(comp, path)
            if path != "" and comppath != None:
                if comp.find(".py") >= 0:
                    tabcommands.append("--tab -t " + comp + " -e \"" + pythonpath + " " + comppath + "\"" + " --working-directory=" + path)
                elif comp.find(".l") >= 0:
                    tabcommands.append("--tab -t " + comp + " -e \"" + invoke_commandpath + " " + delay + " " + euslisppath + " " + comppath + "\"" + " --working-directory=" + path)
                else:
                    tabcommands.append("--tab -t " + comp + " -e \"" + comppath + "\"" + " --working-directory=" + path)

        rtcdcommands.append(rtcdcommand)

    if tabcommands != []:
        sprocs = subprocess.Popen("/usr/bin/gnome-terminal " + terminal_options + " " + " ".join(tabcommands), shell=True)

    time.sleep(0.1)
    #loading & creating components from manager
    manager_no = 0

    for (pack, comp, cxt, ectpack) in zip(packs, comps, cxts, ecxtpacks):
        if comp.find('.so')!=-1:
            cpos=comp.find(':')
            if cpos != -1:
                exec_context = comp[cpos+1:]
                comp = comp[:cpos]
            else:
                exec_context = None

            rtfret , manpath = rtfind.main(['/' + host, '--name=rtmext_manager' + unames[manager_no] + '.mgr', '--type=m'], None)
            path=rtmpack(["find",pack])
            sopath = search_file(comp, path)
            classname = comp[:len(comp)-3]
            initfuncname = classname + "Init"
            if manpath !=[]:
                if exec_context !=None:
                    ec_sofile = exec_context + '.so'
                    ec_initfunc = exec_context + 'Init'
                    if not ectpack == None:
                        path=rtmpack(["find",ectpack])
                    ecpath = search_file( ec_sofile, path)
                    rtmgr.main(['--load=' + str(ecpath),  '--init-func=' + str(ec_initfunc), manpath[0]], None)
                rtmgr.main(['--load=' + str(sopath) ,'--init-func=' + str(initfuncname), manpath[0]], None)
                rtmgr.main(['--create=' + str(classname) + '?instance_name=' + str(cxt) ,manpath[0]], None)
                time.sleep(0.5)
                manager_no += 1
        
    #removing temporary files
    for i in range(manager_no):
        tmpfn = "/tmp/rtcconf" + unames[i] + ".XXX"
        os.remove(tmpfn)

    return [sprocs, rtcdcommands]
예제 #2
0
def rtmrun(pack, comp, cxt, delay, rate=None, ecxtpack=None, host=None, port=None):
    path=rtmpack(["find",pack])
    sproc=None
    pythonpath=commands.getoutput("which python")
    if os.environ.has_key("EUS"):
        if os.environ["EUS"] == "jskrbeusgl":
            euslisppath=commands.getoutput("which jskrbeusgl")
    else:
        euslisppath=commands.getoutput("which irteusgl")
    tmppaths=commands.getoutput("which -a invoke_command_with_sleep.sh").split('\n')
    invoke_commandpath=tmppaths[len(tmppaths)-1]

    if host == None:
        host = socket.gethostname()
    if port == None:
        port = 2809

    rtcdcommand = None
    baseno = 2809

    if comp.find('.so')!=-1:
        cpos=comp.find(':')
        if cpos != -1:
            exec_context = comp[cpos+1:]
            comp = comp[:cpos]
        else:
            exec_context = None
        #use rtmgr for creating components    
        uname = '_' + str(cxt)

        tmpfn = "/tmp/rtcconf" + uname + ".XXX"
        tmpconf = open(tmpfn, 'w')
        tmpconf.write("corba.nameservers: " + host + ":" + str(port) + "\n")
        tmpconf.write("logger.enable: NO\n")
        tmpconf.write("manager.instance_name: rtmext_manager" + uname + "\n")
        mmport = ordsum(uname) + baseno
        tmpconf.write("corba.master_manager:" + host + ":" + str(mmport) + "\n")
        tmpconf.write("manager.modules.load_path: ./\n")
        tmpconf.write("manager.modules.abs_path_allowed: yes\n")
        if rate == None:
            rate = 1000
        tmpconf.write("exec_cxt.periodic.rate: "+ str(rate) + "\n")
        if exec_context!=None:
            tmpconf.write("exec_cxt.periodic.type: " + str(exec_context) + "\n")
        tmpconf.close()
        rtcdcommand = "rtcd rtmextmgr -f " + tmpfn + " -d"

        sproc = subprocess.Popen(rtcdcommand, cwd=path, shell=True)

        time.sleep(0.1)
        #loading & creating components
        rtfret , manpath = rtfind.main(['/' + host, '--name=rtmext_manager' + uname + '.mgr', '--type=m'], None)
        sopath = search_file(comp, path)
        classname = comp[:len(comp)-3]
        if exec_context !=None:
            ec_sofile = exec_context + '.so'
            ec_initfunc = exec_context + 'Init'
            if not ecxtpack == None:
                path=rtmpack(["find", ecxtpack])
            ecpath = search_file( ec_sofile, path)
            rtmgr.main(['--load=' + str(ecpath), '--init-func=' + str(ec_initfunc), manpath[0]], None)
        initfuncname = classname + "Init"
        rtmgr.main(['--load=' + str(sopath) , '--init-func=' + str(initfuncname), manpath[0]], None)
        rtmgr.main(['--create=' + str(classname) + '?instance_name=' + str(cxt), manpath[0]], None)
        time.sleep(0.5)

        #removing temporary files
        os.remove(tmpfn)
    else:
        comppath = search_file(comp, path)

        if path != "":
            if comp.find(".py") >= 0:
                sproc = subprocess.Popen(pythonpath + " " + comppath, cwd=path, shell=True)
            elif comp.find(".l") >= 0:
                sproc = subprocess.Popen(invoke_commandpath + " " + delay + " " + euslisppath + " " + comppath, cwd=path, shell=True)
            else:
                sproc = subprocess.Popen(comppath, cwd=path)
        else:
            sproc = None

    return [sproc, rtcdcommand]