From: ptv Date: Fri, 28 Apr 2006 06:39:20 +0000 (+0000) Subject: wnt adopted version of runSalome and killSalome scripts X-Git-Tag: LAST_STABLE_VERSION_21_09_2006_ON_3_2_0~54 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c2c31ffe654c2f70f6d9181c99e405d582a5a458;p=modules%2Fkernel.git wnt adopted version of runSalome and killSalome scripts --- diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index e52a25f88..b26c6ca28 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -22,7 +22,39 @@ def getPiDict(port,appname='salome',full=True): filedict = os.getenv("HOME") + '/' + filedict return filedict +def appliCleanOmniOrbConfig(port): + """ + remove omniorb config files related to the port in SALOME application: + - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_${NSPORT}.cfg + - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_last.cfg + the last is removed only if the link points to the first file. + """ + from Utils_Identity import getShortHostName + appli=os.environ.get("APPLI") + if appli is None: + #Run outside application context + pass + else: + home = os.environ['HOME'] + home='%s/%s'%(home,appli) + hostname=getShortHostName() + omniorb_config = '%s/.omniORB_%s_%s.cfg'%(home,hostname, str(port)) + last_running_config = '%s/.omniORB_%s_last.cfg'%(home, hostname) + if os.access(last_running_config,os.F_OK): + pointedPath = os.readlink(last_running_config) + if pointedPath[0] != '/': + pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath) + if pointedPath == omniorb_config: + os.unlink(last_running_config) + pass + pass + if os.access(omniorb_config,os.F_OK): + os.remove(omniorb_config) + pass + pass + ########## kills all salome processes with the given port ########## + def killMyPort(port): filedict=getPiDict(port) found = 0 @@ -30,11 +62,30 @@ def killMyPort(port): fpid=open(filedict, 'r') found = 1 except: - print "le fichier %s des process SALOME n'est pas accessible"% filedict + print "file %s giving SALOME process id is not readable"% filedict pass if found: - a = os.system("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid >& /dev/null") + #cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'"` ; echo $pid > /tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log' + #a = os.system(cmd) + try: + fpidomniNames=open('/tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log') + prc = fpidomniNames.read() + fpidomniNames.close() + if prc != None : + for field in prc.split(" ") : + if field == "omniNames" : + if pidfield != "egrep" : + print 'stop process '+pidfield+' : omniNames' + if sys.platform == "win32": + import win32pm + win32pm.killpid(int(pidfield),0) + else: + os.system('kill -9 '+pidfield) + pidfield = field + except: + pass + try: process_ids=pickle.load(fpid) fpid.close() @@ -43,21 +94,32 @@ def killMyPort(port): for pid, cmd in process_id.items(): print "stop process %s : %s"% (pid, cmd[0]) try: - os.kill(int(pid),signal.SIGKILL) + if sys.platform == "win32": + import win32pm + win32pm.killpid(int(pid),0) + else: + os.kill(int(pid),signal.SIGKILL) except: - print " ------------------ process %s : %s inexistant"% (pid, cmd[0]) + print " ------------------ process %s : %s not found"% (pid, cmd[0]) pass pass except: pass + os.remove(filedict) - pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"") - a = "" + cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"' + pid = commands.getoutput(cmd) + a = "" while pid != "" and len(a.split(" ")) < 2: a = commands.getoutput("pid=`ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"`; kill -9 $pid") pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"") print pid - + + pass + + appliCleanOmniOrbConfig(port) + pass + if __name__ == "__main__": for port in sys.argv[1:]: diff --git a/bin/launchConfigureParser.py b/bin/launchConfigureParser.py index aaebdf34f..2c8fbb15c 100755 --- a/bin/launchConfigureParser.py +++ b/bin/launchConfigureParser.py @@ -55,6 +55,52 @@ def version(): return match.group( 1 ) return '' + +# calculate and return configuration file id in order to unically identify it +# for example: for 3.1.0a1 the id is 301000101 +def version_id( fname ): + vers = fname.split(".") + major = int(vers[0]) + minor = int(vers[1]) + mr = re.search(r'^([0-9]+)([A-Za-z]?)([0-9]*)',vers[2]) + release = dev = 0 + if mr: + release = int(mr.group(1)) + dev1 = dev2 = 0 + if len(mr.group(2)): dev1 = ord(mr.group(2)) + if len(mr.group(3)): dev2 = int(mr.group(3)) + dev = dev1 * 100 + dev2 + ver = major + ver = ver * 100 + minor + ver = ver * 100 + release + ver = ver * 10000 + dev + return ver + +# get user configuration file name +def userFile(): + v = version() + if not v: + return "" # not unknown version + filename = "%s/.%src.%s" % (os.environ['HOME'], appname, v) + if os.path.exists(filename): + return filename # user preferences file for the current version exists + # initial id + id0 = version_id( v ) + # get all existing user preferences files + files = glob.glob( os.environ['HOME'] + "/." + appname + "rc.*" ) + f2v = {} + for file in files: + match = re.search( r'\.%src\.([a-zA-Z0-9.]+)$'%appname, file ) + if match: f2v[file] = match.group(1) + last_file = "" + last_version = 0 + for file in f2v: + ver = version_id( f2v[file] ) + if abs(last_version-id0) > abs(ver-id0): + last_version = ver + last_file = file + return last_file + # ----------------------------------------------------------------------------- ### xml reader for launch configuration file usage @@ -63,7 +109,7 @@ section_to_skip = "" class xml_parser: def __init__(self, fileName, _opts ): - print "Processing ",fileName + print "Configure parser: processing %s ..." % fileName self.space = [] self.opts = _opts self.section = section_to_skip @@ -161,9 +207,22 @@ class xml_parser: # - command line config_var = appname+'Config' +# set resources variables if not yet set +if os.getenv("GUI_ROOT_DIR"): + if not os.getenv("SUITRoot"): + os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome" + if not os.getenv(config_var): + os.environ[config_var] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources" + pass +else : + if not os.getenv("SUITRoot"): + os.environ["SUITRoot"] = "" + if not os.getenv(config_var): + os.environ[config_var] = "" + dirs = os.environ[config_var] #abd error om win32 path like W:\dir\di1 -print 'Search configuration file in dir ', dirs +#print 'Search configuration file in dir ', dirs if os.sys.platform == 'win32': dirs = re.split('[;]', dirs ) else: @@ -182,17 +241,16 @@ for dir in dirs: p = xml_parser(filename, _opts) _opts = p.opts except: - print 'Can not read launch configuration file ', filename + print "Configure parser: Error : can not read configuration file %s" % filename continue # SalomeApprc file in user's catalogue -filename = os.environ['HOME']+'/.'+appname+'rc.'+version() +filename = userFile() try: p = xml_parser(filename, _opts) _opts = p.opts except: - print 'Can not read launch configuration file ', filename - + print 'Configure parser: Error : can not read user configuration file' args = _opts @@ -244,8 +302,6 @@ def options_parser(line): list = [] pass - #print "source=",source - result = {} i = 0 while i < len(source): @@ -274,7 +330,6 @@ def options_parser(line): cmd_opts = {} try: cmd_opts = options_parser(sys.argv[1:]) - #print "opts=",cmd_opts kernel_root_dir=os.environ["KERNEL_ROOT_DIR"] except: cmd_opts["h"] = 1 @@ -285,7 +340,7 @@ except: opterror=0 for opt in cmd_opts: if not opt in ("h","g","l","f","x","m","e","s","c","p","k","t","i","r"): - print "command line error: -", opt + print "Configure parser: Error : command line error : -%s" % opt opterror=1 if opterror == 1: @@ -355,9 +410,23 @@ for opt in cmd_opts: pass pass +# if --modules (-m) command line option is not given +# try SALOME_MODULES environment variable +if not cmd_opts.has_key( "m" ) and os.getenv( "SALOME_MODULES" ): + args[modules_nam] = re.split( "[:;,]", os.getenv( "SALOME_MODULES" ) ) + pass + # 'terminal' must be processed in the end: to deny any 'gui' options if 't' in cmd_opts: args[gui_nam] = 0 pass -#print "args=",args +# now modify SalomeAppConfig environment variable +if os.sys.platform == 'win32': + dirs = re.split('[;]', os.environ[config_var] ) +else: + dirs = re.split('[;|:]', os.environ[config_var] ) +for m in args[modules_nam]: + if m not in ["KERNEL", "GUI", ""] and os.getenv("%s_ROOT_DIR"%m): + dirs.append( os.getenv("%s_ROOT_DIR"%m) + "/share/salome/resources" ) +os.environ[config_var] = ":".join(dirs) diff --git a/bin/nameserver.py b/bin/nameserver.py new file mode 100755 index 000000000..c07a3fbfa --- /dev/null +++ b/bin/nameserver.py @@ -0,0 +1,98 @@ +#!/usr/bin/env python + +import sys, os, re +#import commands +from server import * + +# ----------------------------------------------------------------------------- + +class NamingServer(Server): + XTERM="" + USER=os.getenv('USER') + if USER is None: + USER='anonymous' + #os.system("mkdir -m 777 -p /tmp/logs") + LOGDIR="/tmp/logs/" + USER + + def initNSArgs(self): + if sys.platform == "win32": + # temporarily using home directory for Namning Service logs + # to be replaced with TEMP later... + os.environ["BaseDir"]=os.environ["HOME"] + else: + os.environ["BaseDir"]="/tmp" + + try: + os.mkdir(os.environ["BaseDir"] + "/logs") + except: + #print "Can't create " + os.environ["BaseDir"] + "/logs" + pass + + upath = os.environ["BaseDir"] + "/logs/" + os.environ["Username"] + + try: + os.mkdir(upath) + except: + #print "Can't create " + upath + pass + + #os.system("touch " + upath + "/dummy") + for fname in os.listdir(upath): + try: + os.remove(upath + "/" + fname) + except: + pass + #os.system("rm -f " + upath + "/omninames* " + upath + "/dummy " + upath + "/*.log") + + print "Name Service... " + hname=os.environ["HOST"] #commands.getoutput("hostname") + print "hname=",hname + + f=open(os.environ["OMNIORB_CONFIG"]) + ss=re.findall("NameService=corbaname::" + hname + ":\d+", f.read()) + print "ss = ", ss + f.close() + aPort=re.findall("\d+", ss[0])[0] + + #aSedCommand="s/.*NameService=corbaname::" + hname + ":\([[:digit:]]*\)/\1/" + #print "sed command = ", aSedCommand + #aPort = commands.getoutput("sed -e\"" + aSedCommand + "\"" + os.environ["OMNIORB_CONFIG"]) + print "port=", aPort + if sys.platform == "win32": + #print "start omniNames -start " + aPort + " -logdir " + upath + self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath] + #os.system("start omniNames -start " + aPort + " -logdir " + upath) + else: + self.CMD=['omniNames -start ' , aPort , ' -logdir ' , upath , ' &'] + #os.system("omniNames -start " + aPort + " -logdir " + upath + " &") + + print "ok" + print "to list contexts and objects bound int the context with the specified name : showNS " + + + def initArgs(self): + Server.initArgs(self) + env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + os.getenv("LD_LIBRARY_PATH")] + self.CMD=['xterm', '-e']+ env_ld_library_path + ['python'] + self.initNSArgs() + + +# In LifeCycleCORBA, FactoryServer is started with rsh on the requested +# computer if this Container does not exist. Default is localhost. +# Others Containers are started with start_impl method of FactoryServer Container. +# For using rsh it is necessary to have in the ${HOME} directory a .rhosts file +# Warning : on RedHat the file /etc/hosts contains by default a line like : +# 127.0.0.1 bordolex bordolex.paris1.matra-dtv.fr localhost.localdomain localhost +# (bordolex is the station name). omniNames on bordolex will be accessible from other +# computers only if the computer name is removed on that line like : +# 127.0.0.1 bordolex.paris1.matra-dtv.fr localhost.localdomain localhost + +# To start dynamically Containers on several computers you need to +# put in the ${OMNIORB_CONFIG} file a computer name instead of "localhost" +# example : ORBInitRef NameService=corbaname::dm2s0017 + +# If you need to use several omniNames running on the same computer, you have to : +#1. put in your ${OMNIORB_CONFIG} file a computer name and port number +# example : ORBInitRef NameService=corbaname::dm2s0017:1515 +#2. start omninames with this port number like in orbmodile.py +# example : omniNames -start 1515 -logdir ${BaseDir}/logs/${Username} & diff --git a/bin/orbmodule.py b/bin/orbmodule.py index de17de138..a948ce153 100755 --- a/bin/orbmodule.py +++ b/bin/orbmodule.py @@ -1,53 +1,26 @@ import sys,os,time import string +from nameserver import * + from omniORB import CORBA # Import the stubs for the Naming service import CosNaming -# ----------------------------------------------------------------------------- - -class Server: - XTERM="/usr/bin/X11/xterm -iconic -e " - CMD="" - - def run(self): - #commande=self.XTERM+self.CMD - #print commande - #ier=os.system(commande) - #try: - print "runNS" - import runNS - runNS.startOmni() - #except: - #if ier:print "Commande failed" - #print "Commande failed" - -# ----------------------------------------------------------------------------- - -class NamingServer(Server): - XTERM="" - USER=os.getenv('USER') - if USER is None: - USER='anonymous' - #os.system("mkdir -m 777 -p /tmp/logs") - LOGDIR="/tmp/logs/" + USER - #os.system("mkdir -m 777 -p " + LOGDIR) - # CMD="runNS.sh > " + LOGDIR + "/salomeNS.log 2>&1" # ----------------------------------------------------------------------------- class client: - def __init__(self): + def __init__(self,args): # Initialise the ORB self.orb=CORBA.ORB_init(sys.argv, CORBA.ORB_ID) # Initialise the Naming Service - self.initNS() + self.initNS(args) # -------------------------------------------------------------------------- - def initNS(self): + def initNS(self,args): # Obtain a reference to the root naming context obj = self.orb.resolve_initial_references("NameService") try: @@ -58,18 +31,15 @@ class client: print "Lancement du Naming Service", # On lance le Naming Server (doit etre dans le PATH) - NamingServer().run() + ns = NamingServer(args).run() print "Searching Naming Service ", ncount=0 delta=0.1 while(ncount < 10): ncount += 1 try: - print "1" obj = self.orb.resolve_initial_references("NameService") - print "2", obj self.rootContext = obj._narrow(CosNaming.NamingContext) - print "3" break except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE): self.rootContext = None @@ -128,7 +98,7 @@ class client: # -------------------------------------------------------------------------- - def waitNS(self,name,typobj=None,maxcount=60): + def waitNS(self,name,typobj=None,maxcount=1000): count=0 delta=0.5 print "Searching %s in Naming Service " % name, @@ -153,6 +123,40 @@ class client: # -------------------------------------------------------------------------- + if sys.platform != "win32": + def waitNSPID(self, theName, thePID, theTypObj = None): + aCount = 0 + aDelta = 0.5 + anObj = None + print "Searching %s in Naming Service " % theName, + while(1): + try: + aPid, aStatus = os.waitpid(thePID,os.WNOHANG) + except Exception, exc: + raise "Impossible de trouver %s" % theName + aCount += 1 + anObj = self.Resolve(theName) + if anObj: + print " found in %s seconds " % ((aCount-1)*aDelta) + break + else: + sys.stdout.write('+') + sys.stdout.flush() + time.sleep(aDelta) + pass + pass + + if theTypObj is None: + return anObj + + anObject = anObj._narrow(theTypObj) + if anObject is None: + print "%s exists but is not a %s" % (theName,theTypObj) + return anObject + + + # -------------------------------------------------------------------------- + def ResolveLogger(self, name): context_name=[] context_name.append(CosNaming.NameComponent(name,"")) @@ -194,4 +198,3 @@ class client: print "%s exists but is not a %s" % (name,typobj) return nobj -print "888" \ No newline at end of file diff --git a/bin/runSalome.py b/bin/runSalome.py index f97a63492..edcdeb241 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -1,9 +1,10 @@ #!/usr/bin/env python import sys, os, string, glob, time, pickle +from server import * import orbmodule -process_id = {} +#process_id = {} # salome_subdir variable is used for composing paths like $KERNEL_ROOT_DIR/share/salome/resources, etc. # before moving to SUIT-based gui, instead of salome_subdir there was args['appname'] used. @@ -65,7 +66,9 @@ def get_config(): modules_list = [] if args.has_key("modules"): modules_list += args["modules"] - # KERNEL must be last in the list to locate it at the first place in PATH + # KERNEL must be last in the list to locate it at the first place in PATH + if args["gui"] : + modules_list[:0] = ["GUI"] modules_list[:0] = ["KERNEL"] modules_list.reverse() @@ -75,12 +78,12 @@ def get_config(): for module in modules_list : module_variable=module.upper()+"_ROOT_DIR" if not os.environ.has_key(module_variable): - #print "*******************************************************" - #print "*" - #print "* Environment variable",module_variable,"must be set" - #print "* Module", module, "will be not available" - #print "*" - #print "********************************************************" + print "*******************************************************" + print "*" + print "* Environment variable",module_variable,"must be set" + print "* Module", module, "will be not available" + print "*" + print "********************************************************" to_remove_list.append(module) continue pass @@ -94,6 +97,10 @@ def get_config(): modules_list.remove("KERNEL") pass + while "GUI" in modules_list: + modules_list.remove("GUI") + pass + if "SUPERV" in modules_list and not 'superv' in args['standalone']: args['standalone'].append("superv") pass @@ -107,51 +114,48 @@ def set_env(args, modules_list, modules_root_dir): python_version="python%d.%d" % sys.version_info[0:2] modules_root_dir_list = [] + if args["gui"] : + modules_list = modules_list[:] + ["GUI"] modules_list = modules_list[:] + ["KERNEL"] for module in modules_list : - module_root_dir = modules_root_dir[module] - modules_root_dir_list[:0] = [module_root_dir] - add_path(os.path.join(module_root_dir,"lib",salome_subdir), - "LD_LIBRARY_PATH") - add_path(os.path.join(module_root_dir,"bin",salome_subdir), - "PATH") - if os.path.exists(module_root_dir + "/examples") : - add_path(os.path.join(module_root_dir,"examples"), + if modules_root_dir.has_key(module): + module_root_dir = modules_root_dir[module] + modules_root_dir_list[:0] = [module_root_dir] + add_path(os.path.join(module_root_dir,"lib",salome_subdir), + "LD_LIBRARY_PATH") + add_path(os.path.join(module_root_dir,"bin",salome_subdir), + "PATH") + if os.path.exists(module_root_dir + "/examples") : + add_path(os.path.join(module_root_dir,"examples"), + "PYTHONPATH") + pass + add_path(os.path.join(module_root_dir,"bin",salome_subdir), + "PYTHONPATH") + add_path(os.path.join(module_root_dir,"lib", + python_version,"site-packages", + salome_subdir), + "PYTHONPATH") + add_path(os.path.join(module_root_dir,"lib",salome_subdir), "PYTHONPATH") - add_path(os.path.join(module_root_dir,"bin",salome_subdir), - "PYTHONPATH") - add_path(os.path.join(module_root_dir,"lib", - python_version,"site-packages",salome_subdir), - "PYTHONPATH") - add_path(os.path.join(module_root_dir,"lib",salome_subdir), - "PYTHONPATH") - add_path(os.path.join(module_root_dir,"lib", - python_version,"site-packages",salome_subdir, - "shared_modules"), - "PYTHONPATH") + add_path(os.path.join(module_root_dir,"lib", + python_version,"site-packages", + salome_subdir, + "shared_modules"), + "PYTHONPATH") + pass + pass + os.environ["SALOMEPATH"]=":".join(modules_root_dir_list) - # special path for logger lib if needeed + # set trace environment variable - os.environ["SALOME_trace"]="local" + if not os.environ.has_key("SALOME_trace"): + os.environ["SALOME_trace"]="local" if args['file']: - os.environ["SALOME_trace"]=args['file'][0] + os.environ["SALOME_trace"]="file:"+args['file'][0] if args['logger']: os.environ["SALOME_trace"]="with_logger" - locdir=os.environ['PWD'] - libtracedir=os.path.join(locdir,"libSalomeTrace") - libtrace = os.path.join(modules_root_dir["KERNEL"],"lib", - salome_subdir, - "libSALOMELoggerClient.so.0.0.0") - libtraceln = os.path.join(libtracedir,"libSALOMELocalTrace.so") - aCommand = 'rm -rf ' + libtracedir + "; " - aCommand += 'mkdir ' + libtracedir + "; " - aCommand += 'ln -s ' + libtrace + " " + libtraceln + "; " - aCommand += 'ln -s ' + libtrace + " " + libtraceln + ".0; " - aCommand += 'ln -s ' + libtrace + " " + libtraceln + ".0.0.0; " - os.system(aCommand) - add_path(libtracedir, "LD_LIBRARY_PATH") # set environment for SMESH plugins @@ -163,10 +167,18 @@ def set_env(args, modules_list, modules_root_dir): pass if args.has_key("SMESH_plugins"): for plugin in args["SMESH_plugins"]: - if os.environ.has_key(plugin.upper()+"_ROOT_DIR"): + plugin_root = "" + if os.environ.has_key(plugin+"_ROOT_DIR"): + plugin_root = os.environ[plugin+"_ROOT_DIR"] + else: + # workaround to avoid modifications of existing environment + if os.environ.has_key(plugin.upper()+"_ROOT_DIR"): + plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"] + pass + pass + if plugin_root != "": os.environ["SMESH_MeshersList"] \ = os.environ["SMESH_MeshersList"]+":"+plugin - plugin_root = os.environ[plugin.upper()+"_ROOT_DIR"] if not os.environ.has_key("SALOME_"+plugin+"Resources"): os.environ["SALOME_"+plugin+"Resources"] \ = plugin_root+"/share/"+args["appname"]+"/resources" @@ -186,7 +198,31 @@ def set_env(args, modules_list, modules_root_dir): # set environment for SUPERV module os.environ["ENABLE_MACRO_NODE"]="1" - + # set resources variables if not yet set + # Done now by launchConfigureParser.py + #if os.getenv("GUI_ROOT_DIR"): + #if not os.getenv("SUITRoot"): os.environ["SUITRoot"] = os.getenv("GUI_ROOT_DIR") + "/share/salome" + #if not os.getenv("SalomeAppConfig"): os.environ["SalomeAppConfig"] = os.getenv("GUI_ROOT_DIR") + "/share/salome/resources" + + # set CSF_PluginDefaults variable only if it is not customized + # by the user + if not os.getenv("CSF_PluginDefaults"): + os.environ["CSF_PluginDefaults"] \ + = os.path.join(modules_root_dir["KERNEL"],"share", + salome_subdir,"resources") + os.environ["CSF_SALOMEDS_ResourcesDefaults"] \ + = os.path.join(modules_root_dir["KERNEL"],"share", + salome_subdir,"resources") + + if "GEOM" in modules_list: + print "GEOM OCAF Resources" + os.environ["CSF_GEOMDS_ResourcesDefaults"] \ + = os.path.join(modules_root_dir["GEOM"],"share", + salome_subdir,"resources") + print "GEOM Shape Healing Resources" + os.environ["CSF_ShHealingDefaults"] \ + = os.path.join(modules_root_dir["GEOM"],"share", + salome_subdir,"resources") # ----------------------------------------------------------------------------- @@ -234,43 +270,6 @@ def kill_salome(args): elif args['portkill']: givenPortKill(str(args['port'])) -# ----------------------------------------------------------------------------- -# -# Definition des classes d'objets pour le lancement des Server CORBA -# - -class Server: - """Generic class for CORBA server launch""" - - def initArgs(self): - self.CMD=[] - self.ARGS=[] - if self.args['xterm']: - self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold'] - - def __init__(self,args): - self.args=args - self.initArgs() - - - def run(self): - global process_id - myargs=self.ARGS - if self.args['xterm']: - # (Debian) send LD_LIBRARY_PATH to children shells (xterm) - env_ld_library_path=['env', 'LD_LIBRARY_PATH=' - + os.getenv("LD_LIBRARY_PATH")] - myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path - command = myargs + self.CMD - print "command = ", command - if sys.platform == "win32": - #pid = os.spawnv(os.P_NOWAIT, command[0], command) - os.system("start " + string.join(command, " ")) - pid = 0 - else: - pid = os.spawnvp(os.P_NOWAIT, command[0], command) - process_id[pid]=self.CMD - class InterpServer(Server): def __init__(self,args): @@ -283,8 +282,13 @@ class InterpServer(Server): global process_id command = self.CMD print "command = ", command - pid = os.spawnvp(os.P_NOWAIT, command[0], command) + if sys.platform == "win32": + import win32pm + pid = win32pm.spawnpid( string.join(command, " ") ) + else: + pid = os.spawnvp(os.P_NOWAIT, command[0], command) process_id[pid]=self.CMD + self.PID = pid # --- @@ -305,14 +309,21 @@ class CatalogServer(Server): cata_path=[] list_modules = modules_list[:] list_modules.reverse() - for module in ["KERNEL"] + list_modules: - module_root_dir=modules_root_dir[module] - module_cata=module+"Catalog.xml" - print " ", module_cata - cata_path.extend( - glob.glob(os.path.join(module_root_dir, - "share",salome_subdir, - "resources",module_cata))) + if self.args["gui"] : + list_modules = ["KERNEL", "GUI"] + list_modules + else : + list_modules = ["KERNEL"] + list_modules + for module in list_modules: + if modules_root_dir.has_key(module): + module_root_dir=modules_root_dir[module] + module_cata=module+"Catalog.xml" + #print " ", module_cata + cata_path.extend( + glob.glob(os.path.join(module_root_dir, + "share",salome_subdir, + "resources",module_cata))) + pass + pass self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2 # --- @@ -380,29 +391,12 @@ class LoggerServer(Server): # --- -# class SessionLoader(Server): -# def __init__(self,args): -# self.args=args -# self.initArgs() -# self.CMD=['SALOME_Session_Loader'] -# if "cppContainer" in self.args['standalone'] \ -# or "cppContainer" in self.args['embedded']: -# self.CMD=self.CMD+['CPP'] -# if "pyContainer" in self.args['standalone'] \ -# or "pyContainer" in self.args['embedded']: -# self.CMD=self.CMD+['PY'] -# if "supervContainer" in self.args['containers'] \ -# or "supervContainer" in self.args['standalone']: -# self.CMD=self.CMD+['SUPERV'] -# if self.args['gui']: -# self.CMD=self.CMD+['GUI'] -# print self.CMD - -# --- - class SessionServer(Server): def __init__(self,args): - self.args=args + self.args = args.copy() + # Bug 11512 (Problems with runSalome --xterm on Mandrake and Debian Sarge) + self.args['xterm']=0 + # self.initArgs() if sys.platform == "win32": self.SCMD1=[os.environ["GUI_ROOT_DIR"] + "/win32/" + os.environ["BIN_ENV"] + "/" + 'SALOME_Session_Server' + ".exe"] @@ -434,22 +428,33 @@ class SessionServer(Server): self.SCMD2+=['SUPERV'] if self.args['gui']: self.SCMD2+=['GUI'] - if self.args['splash']: + if self.args['splash'] and self.args['gui']: self.SCMD2+=['SPLASH'] + if self.args['noexcepthandler']: + self.SCMD2+=['noexcepthandler'] + if self.args.has_key('modules'): + self.SCMD2+=['--modules ('] + for mod in self.args['modules']: + self.SCMD2+=[mod + ':'] + self.SCMD2+=[')'] def setpath(self,modules_list,modules_root_dir): cata_path=[] list_modules = modules_list[:] list_modules.reverse() - for module in ["KERNEL"] + list_modules: + if self.args["gui"] : + list_modules = ["KERNEL", "GUI"] + list_modules + else : + list_modules = ["KERNEL"] + list_modules + for module in list_modules: module_root_dir=modules_root_dir[module] module_cata=module+"Catalog.xml" - print " ", module_cata + #print " ", module_cata cata_path.extend( glob.glob(os.path.join(module_root_dir,"share", salome_subdir,"resources", module_cata))) - if 'moduleCatalog' in self.args['embedded']: + if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']): self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2 else: self.CMD=self.SCMD1 + self.SCMD2 @@ -465,31 +470,37 @@ class ContainerManagerServer(Server): else: self.SCMD1=['SALOME_ContainerManagerServer'] self.SCMD2=[] - if 'registry' in self.args['embedded']: - self.SCMD1+=['--with','Registry', - '(','--salome_session','theSession',')'] - if 'moduleCatalog' in self.args['embedded']: - self.SCMD1+=['--with','ModuleCatalog','(','-common'] - self.SCMD2+=['-personal', - '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')'] - if 'study' in self.args['embedded']: - self.SCMD2+=['--with','SALOMEDS','(',')'] - if 'cppContainer' in self.args['embedded']: - self.SCMD2+=['--with','Container','(','FactoryServer',')'] + if args["gui"] : + if 'registry' in self.args['embedded']: + self.SCMD1+=['--with','Registry', + '(','--salome_session','theSession',')'] + if 'moduleCatalog' in self.args['embedded']: + self.SCMD1+=['--with','ModuleCatalog','(','-common'] + self.SCMD2+=['-personal', + '${HOME}/Salome/resources/CatalogModulePersonnel.xml',')'] + if 'study' in self.args['embedded']: + self.SCMD2+=['--with','SALOMEDS','(',')'] + if 'cppContainer' in self.args['embedded']: + self.SCMD2+=['--with','Container','(','FactoryServer',')'] def setpath(self,modules_list,modules_root_dir): cata_path=[] list_modules = modules_list[:] list_modules.reverse() + if self.args["gui"] : + list_modules = ["GUI"] + list_modules for module in ["KERNEL"] + list_modules: - module_root_dir=modules_root_dir[module] - module_cata=module+"Catalog.xml" - print " ", module_cata - cata_path.extend( - glob.glob(os.path.join(module_root_dir,"share", - self.args['appname'],"resources", - module_cata))) - if 'moduleCatalog' in self.args['embedded']: + if modules_root_dir.has_key(module): + module_root_dir=modules_root_dir[module] + module_cata=module+"Catalog.xml" + #print " ", module_cata + cata_path.extend( + glob.glob(os.path.join(module_root_dir,"share", + self.args['appname'],"resources", + module_cata))) + pass + pass + if (self.args["gui"]) & ('moduleCatalog' in self.args['embedded']): self.CMD=self.SCMD1 + [string.join(cata_path,':')] + self.SCMD2 else: self.CMD=self.SCMD1 + self.SCMD2 @@ -513,7 +524,13 @@ class NotifyServer(Server): def startGUI(): """Salome Session Graphic User Interface activation""" + import Engines import SALOME + import SALOMEDS + import SALOME_ModuleCatalog + reload(Engines) + reload(SALOME) + reload(SALOMEDS) import SALOME_Session_idl session=clt.waitNS("/Kernel/Session",SALOME.Session) session.GetInterface() @@ -525,20 +542,12 @@ def startSalome(args, modules_list, modules_root_dir): init_time = os.times() print "startSalome ", args - print "sysPATH=",sys.path # # Initialisation ORB et Naming Service # - clt=orbmodule.client() - - # - # Lancement Session Server - - mySessionServ = SessionServer(args) - mySessionServ.setpath(modules_list,modules_root_dir) - mySessionServ.run() + clt=orbmodule.client(args) # (non obligatoire) Lancement Logger Server # et attente de sa disponibilite dans le naming service @@ -552,32 +561,47 @@ def startSalome(args, modules_list, modules_root_dir): # Notify Server launch # - #print "Notify Server to launch" - #mpv - #myServer=NotifyServer(args,modules_root_dir) - #myServer.run() +# print "Notify Server to launch" + +# myServer=NotifyServer(args,modules_root_dir) +# myServer.run() + + # Lancement Session Server (to show splash ASAP) + # + + if args["gui"]: + mySessionServ = SessionServer(args) + mySessionServ.setpath(modules_list,modules_root_dir) + mySessionServ.run() # # Lancement Registry Server, # attente de la disponibilite du Registry dans le Naming Service # - if 'registry' not in args['embedded']: + if ('registry' not in args['embedded']) | (args["gui"] == 0) : myServer=RegistryServer(args) myServer.run() - clt.waitNS("/Registry") + if sys.platform == "win32": + clt.waitNS("/Registry") + else: + clt.waitNSPID("/Registry",myServer.PID) # # Lancement Catalog Server, # attente de la disponibilite du Catalog Server dans le Naming Service # - if 'moduleCatalog' not in args['embedded']: + + if ('moduleCatalog' not in args['embedded']) | (args["gui"] == 0): cataServer=CatalogServer(args) cataServer.setpath(modules_list,modules_root_dir) cataServer.run() import SALOME_ModuleCatalog - clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog) + if sys.platform == "win32": + clt.waitNS("/Kernel/ModulCatalog",SALOME_ModuleCatalog.ModuleCatalog) + else: + clt.waitNSPID("/Kernel/ModulCatalog",cataServer.PID,SALOME_ModuleCatalog.ModuleCatalog) # # Lancement SalomeDS Server, @@ -602,11 +626,14 @@ def startSalome(args, modules_list, modules_root_dir): salome_subdir,"resources") print "ARGS = ",args - if 'study' not in args['embedded']: + if ('study' not in args['embedded']) | (args["gui"] == 0): print "RunStudy" myServer=SalomeDSServer(args) myServer.run() - clt.waitNS("/myStudyManager") + if sys.platform == "win32": + clt.waitNS("/myStudyManager") + else: + clt.waitNSPID("/myStudyManager",myServer.PID) # # Lancement ContainerManagerServer @@ -635,7 +662,10 @@ def startSalome(args, modules_list, modules_root_dir): if 'cppContainer' in args['standalone']: myServer=ContainerCPPServer(args) myServer.run() - clt.waitNS("/Containers/" + theComputer + "/FactoryServer") + if sys.platform == "win32": + clt.waitNS("/Containers/" + theComputer + "/FactoryServer") + else: + clt.waitNSPID("/Containers/" + theComputer + "/FactoryServer",myServer.PID) # # Lancement Container Python local, @@ -646,7 +676,10 @@ def startSalome(args, modules_list, modules_root_dir): if 'pyContainer' in args['standalone']: myServer=ContainerPYServer(args) myServer.run() - clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy") + if sys.platform == "win32": + clt.waitNS("/Containers/" + theComputer + "/FactoryServerPy") + else: + clt.waitNSPID("/Containers/" + theComputer + "/FactoryServerPy",myServer.PID) # # Lancement Container Supervision local, @@ -657,15 +690,29 @@ def startSalome(args, modules_list, modules_root_dir): if 'supervContainer' in args['standalone']: myServer=ContainerSUPERVServer(args) myServer.run() - clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer") -##---------------- - + if sys.platform == "win32": + clt.waitNS("/Containers/" + theComputer + "/SuperVisionContainer") + else: + clt.waitNSPID("/Containers/" + theComputer + "/SuperVisionContainer",myServer.PID) + + # # Attente de la disponibilite du Session Server dans le Naming Service # - - import SALOME - import SALOME_Session_idl - session=clt.waitNS("/Kernel/Session",SALOME.Session) + + if args["gui"]: +##---------------- + import Engines + import SALOME + import SALOMEDS + import SALOME_ModuleCatalog + reload(Engines) + reload(SALOME) + reload(SALOMEDS) + import SALOME_Session_idl + if sys.platform == "win32": + session=clt.waitNS("/Kernel/Session",SALOME.Session) + else: + session=clt.waitNSPID("/Kernel/Session",mySessionServ.PID,SALOME.Session) end_time = os.times() print @@ -699,7 +746,6 @@ def startSalome(args, modules_list, modules_root_dir): anInterp=InterpServer(args) anInterp.run() - print "sysPATH2=",sys.path return clt # ----------------------------------------------------------------------------- @@ -710,6 +756,7 @@ def useSalome(args, modules_list, modules_root_dir): save list of process, give info to user, show registered objects in Naming Service. """ + global process_id clt=None try: @@ -722,12 +769,10 @@ def useSalome(args, modules_list, modules_root_dir): print "--- erreur au lancement Salome ---" #print process_id - -# filedict = '/tmp/' + os.getenv('USER') + "_" + str(args['port']) \ -# + '_' + args['appname'].upper() + '_pidict' -# replaced args['appname'] by "SALOME" because in killSalome.py use of 'SALOME' in file name is hardcoded. - filedict = os.getenv("HOME") + '/' + os.getenv('USER') + "_" + str(args['port']) \ - + '_' + 'SALOME' + '_pidict' + + from killSalomeWithPort import getPiDict + filedict = getPiDict(args['port']) + process_ids = [] try: fpid=open(filedict, 'r') diff --git a/bin/salomeConsole.py b/bin/salomeConsole.py index 5ce7cec64..9373022d2 100755 --- a/bin/salomeConsole.py +++ b/bin/salomeConsole.py @@ -79,7 +79,6 @@ clt.showNS() session=clt.waitNS("/Kernel/Session") catalog=clt.waitNS("/Kernel/ModulCatalog") studyMgr=clt.waitNS("/myStudyManager") -lcc = LifeCycleCORBA.LifeCycleCORBA(clt.orb) - -#c=lcc.FindOrStartContainer("","totoPy") -#print c +import salome +salome.salome_init() +from salome import lcc diff --git a/bin/server.py b/bin/server.py new file mode 100755 index 000000000..a0718cdfc --- /dev/null +++ b/bin/server.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +import sys, string +process_id = {} + +# ----------------------------------------------------------------------------- +# +# Definition des classes d'objets pour le lancement des Server CORBA +# + +class Server: + """Generic class for CORBA server launch""" + + def initArgs(self): + self.PID=None + self.CMD=[] + self.ARGS=[] + if self.args['xterm']: + self.ARGS=['xterm', '-iconic', '-sb', '-sl', '500', '-hold'] + + def __init__(self,args): + self.args=args + self.initArgs() + + + def run(self): + global process_id + myargs=self.ARGS + if self.args['xterm']: + # (Debian) send LD_LIBRARY_PATH to children shells (xterm) + env_ld_library_path=['env', 'LD_LIBRARY_PATH=' + + os.getenv("LD_LIBRARY_PATH")] + myargs = myargs +['-T']+self.CMD[:1]+['-e'] + env_ld_library_path + command = myargs + self.CMD + print "command = ", command + if sys.platform == "win32": + import win32pm + #cmd_str = "\"" + string.join(command, " ") + "\"" + #print cmd_str + #pid = win32pm.spawnpid( cmd_str ) + pid = win32pm.spawnpid( string.join(command, " ") ) + else: + pid = os.spawnvp(os.P_NOWAIT, command[0], command) + process_id[pid]=self.CMD + self.PID = pid