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,hidden=True):
27 Get file with list of SALOME processes.
28 This file is located in the user's home directory
29 and named .<user>_<host>_<port>_SALOME_pidict
37 - appname : application name (default is 'SALOME')
38 - full : if True, full path to the file is returned, otherwise only file name is returned
39 - hidden : if True, file name is prefixed with . (dot) symbol; this internal parameter is used
40 to support compatibility with older versions of SALOME
42 from salome_utilities import generateFileName, getTmpDir
45 # full path to the pidict file is requested
47 # new-style dot-prefixed pidict files
48 # are in the system-dependant temporary diretory
51 # old-style non-dot-prefixed pidict files
52 # are in the user's home directory
53 dir = os.getenv("HOME")
56 return generateFileName(dir,
62 with_app=appname.upper())
64 def appliCleanOmniOrbConfig(port):
66 Remove omniorb config files related to the port in SALOME application:
67 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_${NSPORT}.cfg
68 - ${HOME}/${APPLI}/.omniORB_last.cfg
69 the last is removed only if the link points to the first file.
71 from salome_utilities import generateFileName
72 home = os.getenv("HOME")
73 appli = os.getenv("APPLI")
75 #Run outside application context
78 dir = os.path.join(home, appli)
79 omniorb_config = generateFileName(dir, prefix="omniORB",
84 last_running_config = generateFileName(dir, prefix="omniORB",
88 if os.access(last_running_config,os.F_OK):
89 pointedPath = os.readlink(last_running_config)
90 if pointedPath[0] != '/':
91 pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath)
92 if pointedPath == omniorb_config:
93 os.unlink(last_running_config)
96 if os.access(omniorb_config,os.F_OK):
97 os.remove(omniorb_config)
102 ########## kills all salome processes with the given port ##########
104 def killMyPort(port):
106 Kill SALOME session running on the specified port.
110 # new-style dot-prefixed pidict file
111 filedict = getPiDict(port, hidden=True)
112 # provide compatibility with old-style pidict file (not dot-prefixed)
113 if not os.path.exists(filedict): filedict = getPiDict(port, hidden=False)
116 fpid = open(filedict, 'r')
118 from salome_utilities import generateFileName
119 fpidomniNames = generateFileName(os.path.join('/tmp/logs', os.getenv('USER')),
121 suffix="Pid_omniNames",
124 if not sys.platform == 'win32':
125 cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start %s"` ; echo $pid > %s' % ( str(port), fpidomniNames )
129 fpidomniNamesFile = open(fpidomniNames)
130 lines = fpidomniNamesFile.readlines()
131 fpidomniNamesFile.close()
132 os.remove(fpidomniNames)
135 pidfield = l.split()[0] # pid should be at the first position
136 if sys.platform == "win32":
138 if verbose(): print 'stop process '+pidfield+' : omniNames'
139 win32pm.killpid(int(pidfield),0)
141 if verbose(): print 'stop process '+pidfield+' : omniNames'
142 os.kill(int(pidfield),signal.SIGKILL)
153 process_ids=pickle.load(fpid)
155 for process_id in process_ids:
156 for pid, cmd in process_id.items():
157 if verbose(): print "stop process %s : %s"% (pid, cmd[0])
159 if sys.platform == "win32":
161 win32pm.killpid(int(pid),0)
163 os.kill(int(pid),signal.SIGKILL)
167 if verbose(): print " ------------------ process %s : %s not found"% (pid, cmd[0])
169 pass # for pid, cmd ...
170 pass # for process_id ...
176 cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"'
177 pid = commands.getoutput(cmd)
179 while pid and len(a.split()) < 2:
180 a = commands.getoutput("kill -9 " + pid)
181 pid = commands.getoutput(cmd)
186 print "Cannot find or open SALOME PIDs file for port", port
189 appliCleanOmniOrbConfig(port)
192 if __name__ == "__main__":
193 for port in sys.argv[1:]: