3 # Copyright (C) 2005 OPEN CASCADE, CEA, EDF R&D, LEG
4 # PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 import os, sys, pickle, signal, commands
23 from launchConfigureParser import verbose
25 def getPiDict(port,appname='salome',full=True):
26 from Utils_Identity import getShortHostName
28 # get hostname by special function in all cases to
29 # have always same result in lower case at win32
30 host = getShortHostName()
32 host = os.getenv("HOSTNAME")
34 host = os.getenv("HOST")
37 filedict.append( os.getenv('USER') ) # user name
38 filedict.append( host ) # host name
39 filedict.append( str(port) ) # port number
40 filedict.append( appname.upper() ) # application name
41 filedict.append( 'pidict' ) # constant part
43 filedict = '_'.join(filedict)
45 filedict = os.getenv("HOME") + '/' + filedict
48 def appliCleanOmniOrbConfig(port):
50 remove omniorb config files related to the port in SALOME application:
51 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_${NSPORT}.cfg
52 - ${HOME}/${APPLI}/.omniORB_last.cfg
53 the last is removed only if the link points to the first file.
55 from Utils_Identity import getShortHostName
56 appli=os.environ.get("APPLI")
58 #Run outside application context
61 home = os.environ['HOME']
62 home='%s/%s'%(home,appli)
63 hostname=getShortHostName()
64 omniorb_config = '%s/.omniORB_%s_%s.cfg'%(home,hostname, str(port))
65 last_running_config = '%s/.omniORB_last.cfg'%(home)
66 if os.access(last_running_config,os.F_OK):
67 pointedPath = os.readlink(last_running_config)
68 if pointedPath[0] != '/':
69 pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath)
70 if pointedPath == omniorb_config:
71 os.unlink(last_running_config)
74 if os.access(omniorb_config,os.F_OK):
75 os.remove(omniorb_config)
79 ########## kills all salome processes with the given port ##########
82 filedict=getPiDict(port)
85 fpid=open(filedict, 'r')
88 print "file %s giving SALOME process id is not readable"% filedict
92 if not sys.platform == 'win32':
93 cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'"` ; echo $pid > /tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log'
96 fpidomniNames=open('/tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log')
97 prc = fpidomniNames.read()
100 for field in prc.split(" ") :
101 if field == "omniNames" :
102 if pidfield != "egrep" :
103 if sys.platform == "win32":
105 print 'stop process '+pidfield+' : omniNames'
106 win32pm.killpid(int(pidfield),0)
108 if verbose(): print 'stop process '+pidfield+' : omniNames'
109 os.system('kill -9 '+pidfield)
115 process_ids=pickle.load(fpid)
117 for process_id in process_ids:
119 for pid, cmd in process_id.items():
120 if verbose(): print "stop process %s : %s"% (pid, cmd[0])
122 if sys.platform == "win32":
124 win32pm.killpid(int(pid),0)
126 os.kill(int(pid),signal.SIGKILL)
128 if verbose(): print " ------------------ process %s : %s not found"% (pid, cmd[0])
135 cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"'
136 pid = commands.getoutput(cmd)
138 while pid != "" and len(a.split(" ")) < 2:
139 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")
140 pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
145 appliCleanOmniOrbConfig(port)
149 if __name__ == "__main__":
150 for port in sys.argv[1:]: