2 import os, sys, pickle, signal, commands
4 def getPiDict(port,appname='salome',full=True):
5 from Utils_Identity import getShortHostName
7 host = os.getenv("HOSTNAME")
9 host = os.getenv("HOST")
11 host = getShortHostName()
14 filedict.append( os.getenv('USER') ) # user name
15 filedict.append( host ) # host name
16 filedict.append( str(port) ) # port number
17 filedict.append( appname.upper() ) # application name
18 filedict.append( 'pidict' ) # constant part
20 filedict = '_'.join(filedict)
22 filedict = os.getenv("HOME") + '/' + filedict
25 def appliCleanOmniOrbConfig(port):
27 remove omniorb config files related to the port in SALOME application:
28 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_${NSPORT}.cfg
29 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_last.cfg
30 the last is removed only if the link points to the first file.
32 from Utils_Identity import getShortHostName
33 appli=os.environ.get("APPLI")
35 #Run outside application context
38 home = os.environ['HOME']
39 home='%s/%s'%(home,appli)
40 hostname=getShortHostName()
41 omniorb_config = '%s/.omniORB_%s_%s.cfg'%(home,hostname, str(port))
42 last_running_config = '%s/.omniORB_%s_last.cfg'%(home, hostname)
43 if os.access(last_running_config,os.F_OK):
44 pointedPath = os.readlink(last_running_config)
45 if pointedPath[0] != '/':
46 pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath)
47 if pointedPath == omniorb_config:
48 os.unlink(last_running_config)
51 if os.access(omniorb_config,os.F_OK):
52 os.remove(omniorb_config)
56 ########## kills all salome processes with the given port ##########
59 filedict=getPiDict(port)
62 fpid=open(filedict, 'r')
65 print "file %s giving SALOME process id is not readable"% filedict
69 cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'"` ; echo $pid > /tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log'
72 fpidomniNames=open('/tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log')
73 prc = fpidomniNames.read()
76 for field in prc.split(" ") :
77 if field == "omniNames" :
78 if pidfield != "egrep" :
79 print 'stop process '+pidfield+' : omniNames'
80 os.system('kill -9 '+pidfield)
86 process_ids=pickle.load(fpid)
88 for process_id in process_ids:
90 for pid, cmd in process_id.items():
91 print "stop process %s : %s"% (pid, cmd[0])
93 os.kill(int(pid),signal.SIGKILL)
95 print " ------------------ process %s : %s not found"% (pid, cmd[0])
102 cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"'
103 pid = commands.getoutput(cmd)
105 while pid != "" and len(a.split(" ")) < 2:
106 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")
107 pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
112 appliCleanOmniOrbConfig(port)
116 if __name__ == "__main__":
117 for port in sys.argv[1:]: