2 import os, sys, pickle, signal, commands
4 def getPiDict(port,appname='salome',full=True):
5 from Utils_Identity import getShortHostName
7 # get hostname by special function in all cases to
8 # have always same result in lower case at win32
9 host = getShortHostName()
11 host = os.getenv("HOSTNAME")
13 host = os.getenv("HOST")
16 filedict.append( os.getenv('USER') ) # user name
17 filedict.append( host ) # host name
18 filedict.append( str(port) ) # port number
19 filedict.append( appname.upper() ) # application name
20 filedict.append( 'pidict' ) # constant part
22 filedict = '_'.join(filedict)
24 filedict = os.getenv("HOME") + '/' + filedict
27 def appliCleanOmniOrbConfig(port):
29 remove omniorb config files related to the port in SALOME application:
30 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_${NSPORT}.cfg
31 - ${HOME}/${APPLI}/.omniORB_${HOSTNAME}_last.cfg
32 the last is removed only if the link points to the first file.
34 from Utils_Identity import getShortHostName
35 appli=os.environ.get("APPLI")
37 #Run outside application context
40 home = os.environ['HOME']
41 home='%s/%s'%(home,appli)
42 hostname=getShortHostName()
43 omniorb_config = '%s/.omniORB_%s_%s.cfg'%(home,hostname, str(port))
44 last_running_config = '%s/.omniORB_%s_last.cfg'%(home, hostname)
45 if os.access(last_running_config,os.F_OK):
46 pointedPath = os.readlink(last_running_config)
47 if pointedPath[0] != '/':
48 pointedPath=os.path.join(os.path.dirname(last_running_config), pointedPath)
49 if pointedPath == omniorb_config:
50 os.unlink(last_running_config)
53 if os.access(omniorb_config,os.F_OK):
54 os.remove(omniorb_config)
58 ########## kills all salome processes with the given port ##########
61 filedict=getPiDict(port)
64 fpid=open(filedict, 'r')
67 print "file %s giving SALOME process id is not readable"% filedict
71 #cmd = 'pid=`ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'"` ; echo $pid > /tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log'
74 fpidomniNames=open('/tmp/logs/'+os.getenv('USER')+"/_"+port+'_Pid_omniNames.log')
75 prc = fpidomniNames.read()
78 for field in prc.split(" ") :
79 if field == "omniNames" :
80 if pidfield != "egrep" :
81 print 'stop process '+pidfield+' : omniNames'
82 if sys.platform == "win32":
84 win32pm.killpid(int(pidfield),0)
86 os.system('kill -9 '+pidfield)
92 process_ids=pickle.load(fpid)
94 for process_id in process_ids:
96 for pid, cmd in process_id.items():
97 print "stop process %s : %s"% (pid, cmd[0])
99 if sys.platform == "win32":
101 win32pm.killpid(int(pid),0)
103 os.kill(int(pid),signal.SIGKILL)
105 print " ------------------ process %s : %s not found"% (pid, cmd[0])
112 cmd='ps -eo pid,command | egrep "[0-9] omniNames -start '+str(port)+'" | sed -e "s%[^0-9]*\([0-9]*\) .*%\\1%g"'
113 pid = commands.getoutput(cmd)
115 while pid != "" and len(a.split(" ")) < 2:
116 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")
117 pid = commands.getoutput("ps -eo pid,command | egrep \"[0-9] omniNames -start "+str(port)+"\" | sed -e \"s%[^0-9]*\([0-9]*\) .*%\\1%g\"")
122 appliCleanOmniOrbConfig(port)
126 if __name__ == "__main__":
127 for port in sys.argv[1:]: