From: Cédric Aguerre Date: Fri, 16 May 2014 10:20:40 +0000 (+0200) Subject: bug fix: omninames kill X-Git-Tag: V7_4_0rc1~2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=75a38dd5aa46aef6300c3e8b6eaced236c0d2f4e;p=modules%2Fkernel.git bug fix: omninames kill --- diff --git a/bin/appliskel/runSalomeScript b/bin/appliskel/runSalomeScript index b50ed6517..fc7452f25 100755 --- a/bin/appliskel/runSalomeScript +++ b/bin/appliskel/runSalomeScript @@ -140,9 +140,8 @@ def copy_files(user,machine,script,infiles,outfiles,directory): import getpass logname = getpass.getuser() tmp_script="/tmp/%s_%s_%s" % (logname,os.getpid(),namescript) - fscript=open(script) - script_text=fscript.read() - fscript.close() + with open(script, 'r') as fscript: + script_text=fscript.read() list_infiles=[] list_outfiles=[] @@ -156,7 +155,7 @@ def copy_files(user,machine,script,infiles,outfiles,directory): #modify the salome script script_text = re.sub(infile,tmp_file,script_text) - # copy the infile to the remote server (into /tmp) + # copy the infile to the remote server cmd="scp %s %s@%s:%s" % (infile,user,machine,tmp_file) print "[ SCP ]",cmd os.system(cmd) @@ -176,9 +175,8 @@ def copy_files(user,machine,script,infiles,outfiles,directory): list_outfiles.append(tmp_file) n=n+1 - fscript=open(tmp_script,'w') - fscript.write(script_text) - fscript.close() + with open(tmp_script,'w') as fscript: + fscript.write(script_text) if directory: #copy the salome script on the remote server @@ -195,6 +193,13 @@ def main(): tmp_script=script print "mode:",mode + print "user:",user + print "machine:",machine + print "port:",port + print "directory:",directory + print "infiles:",infiles + print "outfiles:",outfiles + print "script:",script if mode == "remote": list_infiles, list_outfiles, tmp_script = copy_files(user,machine,script,infiles,outfiles,directory) @@ -202,7 +207,7 @@ def main(): ################################################# # Execution # ################################################# - if directory: + if mode == "remote": print "[ REMOTE ]" # execute runSession from the remote SALOME application @@ -230,7 +235,7 @@ def main(): # Get remote files and clean # ################################################# if mode == "remote": - temp_files=list_infiles+list_outfiles + temp_files=list_infiles+list_outfiles+[tmp_script] #get the outfiles for outfile in outfiles: @@ -247,4 +252,3 @@ def main(): if __name__ == '__main__': main() - diff --git a/bin/killSalomeWithPort.py b/bin/killSalomeWithPort.py index bce9b70be..385454a9a 100755 --- a/bin/killSalomeWithPort.py +++ b/bin/killSalomeWithPort.py @@ -279,12 +279,13 @@ def __killMyPort(port, filedict): try: import re omniNamesPid, omniNamesPort = re.search('(.+?) omniNames -start (.+?) ', out).group(1, 2) - if verbose(): - print "stop omniNames [pid=%s] on port %s"%(omniNamesPid, omniNamesPort) - appliCleanOmniOrbConfig(omniNamesPort) - from PortManager import releasePort - releasePort(omniNamesPort) - os.kill(int(omniNamesPid),signal.SIGKILL) + if omniNamesPort == port: + if verbose(): + print "stop omniNames [pid=%s] on port %s"%(omniNamesPid, omniNamesPort) + appliCleanOmniOrbConfig(omniNamesPort) + from PortManager import releasePort + releasePort(omniNamesPort) + os.kill(int(omniNamesPid),signal.SIGKILL) except (ImportError, AttributeError, OSError) as e: pass except: diff --git a/bin/runSalome.py b/bin/runSalome.py index c819b857c..3c9a517b5 100755 --- a/bin/runSalome.py +++ b/bin/runSalome.py @@ -892,6 +892,7 @@ def foreGround(clt, args): # def runSalome(): + print sys.argv import user clt,args = main() # -- diff --git a/bin/runSession.py b/bin/runSession.py index bd2256b0b..92c6b4705 100644 --- a/bin/runSession.py +++ b/bin/runSession.py @@ -26,6 +26,7 @@ import sys from optparse import OptionParser from NSparam import getNSparams import socket +import subprocess # Use to display newlines (\n) in epilog class MyParser(OptionParser): @@ -104,3 +105,40 @@ def _writeConfigFile(port, host): os.environ['OMNIORB_CONFIG'] = filename # + +# command looks like a Bash command-line: +# script1.py [args] ; script2.py [args] ; ... +def runSession(command): + if command: + sep = ";" + if sys.platform == "win32": + sep= "&" + command = command.split(sep) + outmsg = [] + errmsg = [] + for cmd in command: + save_cmd = cmd + cmd = cmd.strip().split(' ') + #proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + proc = subprocess.Popen(cmd) + (stdoutdata, stderrdata) = proc.communicate() + if stdoutdata: + outmsg.append(stdoutdata) + if stderrdata: + errmsg.append(stderrdata) + + if proc.returncode != 0: + errmsg.append("Error raised when executing command: %s\n"%save_cmd) + if outmsg: + sys.stdout.write("".join(outmsg)) + if errmsg: + sys.stderr.write("".join(errmsg)) + sys.exit(proc.returncode) + + return ("".join(outmsg), "".join(errmsg)) + else: + absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','') + cmd = ["/bin/bash", "--rcfile", absoluteAppliPath + "/.bashrc" ] + proc = subprocess.Popen(cmd, shell=False, close_fds=True) + return proc.communicate() +# diff --git a/bin/salomeContext.py b/bin/salomeContext.py index 5e89ba15c..f4eb21508 100644 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -101,17 +101,17 @@ class SalomeContext: def runSalome(self, args): # Run this module as a script, in order to use appropriate Python interpreter # according to current path (initialized from environment files). - kill = False - for e in args: - if "--shutdown-server" in e: - kill = True - args.remove(e) +# kill = False +# for e in args: +# if "--shutdown-server" in e: +# kill = True +# args.remove(e) absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','') proc = subprocess.Popen(['python', os.path.join(absoluteAppliPath,"bin","salome","salomeContext.py"), pickle.dumps(self), pickle.dumps(args)], shell=False, close_fds=True) msg = proc.communicate() - if kill: - self._killAll(args) + # if kill: + # self._killAll(args) return msg, proc.returncode # @@ -297,38 +297,7 @@ class SalomeContext: scriptArgs = getScriptsAndArgs(args) command = formatScriptsAndArgs(scriptArgs) - if command: - sep = ";" - if sys.platform == "win32": - sep= "&" - command = command.split(sep) - outmsg = [] - errmsg = [] - for cmd in command: - save_cmd = cmd - cmd = cmd.strip().split(' ') - #proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - proc = subprocess.Popen(cmd) - (stdoutdata, stderrdata) = proc.communicate() - if stdoutdata: - outmsg.append(stdoutdata) - if stderrdata: - errmsg.append(stderrdata) - - if proc.returncode != 0: - errmsg.append("Error raised when executing command: %s\n"%save_cmd) - if outmsg: - sys.stdout.write("".join(outmsg)) - if errmsg: - sys.stderr.write("".join(errmsg)) - sys.exit(proc.returncode) - - return ("".join(outmsg), "".join(errmsg)) - else: - absoluteAppliPath = os.getenv('ABSOLUTE_APPLI_PATH','') - cmd = ["/bin/bash", "--rcfile", absoluteAppliPath + "/.bashrc" ] - proc = subprocess.Popen(cmd, shell=False, close_fds=True) - return proc.communicate() + return runSession.runSession(command) # def _runConsole(self, args=[]):