]> SALOME platform Git repositories - modules/yacs.git/commitdiff
Salome HOME
bug fix: omninames kill
authorCédric Aguerre <cedric.aguerre@edf.fr>
Fri, 16 May 2014 10:20:40 +0000 (12:20 +0200)
committerCédric Aguerre <cedric.aguerre@edf.fr>
Fri, 16 May 2014 10:20:40 +0000 (12:20 +0200)
bin/appliskel/runSalomeScript
bin/killSalomeWithPort.py
bin/runSalome.py
bin/runSession.py
bin/salomeContext.py

index b50ed65179f6fd79c805c8535f2d5e635c5a0f01..fc7452f25d151f8bb2f7bd6d21574dc20838f0cc 100755 (executable)
@@ -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()
-
index bce9b70be5161a54b5419c475653f9956c669d41..385454a9aa7d22ec22cd0eaa618941617d1f0533 100755 (executable)
@@ -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:
index c819b857c8513c044d2a650d8e4e63e69cbf26d6..3c9a517b5d969f8ad16e520bc2bf2db0ddbc198c 100755 (executable)
@@ -892,6 +892,7 @@ def foreGround(clt, args):
 #
 
 def runSalome():
+    print sys.argv
     import user
     clt,args = main()
     # --
index bd2256b0b65ec1fae430b18fe97e20c5ba2cade6..92c6b4705936450753b0c0c2375419ef5687f477 100644 (file)
@@ -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()
+#
index 5e89ba15c53228d330164666888811612a2308cc..f4eb21508eb2fbfed0d8be11c1ff1644b98b796b 100644 (file)
@@ -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=[]):