Salome HOME
add runRemote command to salome launcher
authorcrouzet <nicolas.crouzet@cea.fr>
Wed, 5 Dec 2018 09:25:20 +0000 (10:25 +0100)
committerBernard Secher <bernard.secher@cea.fr>
Thu, 28 Mar 2019 13:17:10 +0000 (14:17 +0100)
bin/CMakeLists.txt
bin/runRemote.py [new file with mode: 0644]
bin/salomeContext.py

index 311ae399aaba2113ab79aae3c9797d8be3c3f643..bba6cb6d84f01ec240971220830c4d28ea3914fe 100644 (file)
@@ -48,6 +48,7 @@ SET(SCRIPTS
   runSalome.py
   runSession.py
   runConsole.py
+  runRemote.py
   runTests.py
   ${CMAKE_CURRENT_BINARY_DIR}/salomeContextUtils.py
   salomeContext.py
diff --git a/bin/runRemote.py b/bin/runRemote.py
new file mode 100644 (file)
index 0000000..376f6a6
--- /dev/null
@@ -0,0 +1,101 @@
+# Copyright (C) 2007-2018  CEA/DEN, EDF R&D, OPEN CASCADE
+#
+# Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+# CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+
+import os
+from optparse import OptionParser
+import subprocess
+from salome_utils import getUserName
+from salomeContextUtils import getShortAndExtraArgs
+
+# Use to display newlines (\n) in epilog
+class MyParser(OptionParser):
+    def format_epilog(self, formatter):
+        return self.epilog
+#
+#
+# --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME
+def _writeConfigFile(port, host):
+    path = os.environ['OMNIORB_USER_PATH']
+    kwargs = {'with_username' : getUserName()}
+
+    from ORBConfigFile import writeORBConfigFile
+    [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs)
+
+    os.environ['OMNIORB_CONFIG'] = filename
+#
+
+def runRemote(args):
+    if args is None:
+      args = []
+    usage = "Usage: salome runremote [options] -- command"
+    epilog  = """\n
+Execute command in SALOME environment from a remote call, ssh or rsh.
+salome runremote is used notably to launch containers from a distant salome session.
+
+For example:
+    salome remote -m xxx.cea.fr -p 2810 ls /tmp >/dev/null 2>&1  
+     -> execute the command ls /tmp >/dev/null 2>&1
+
+    salome remote -m xxx.cea.fr -p 2810 SALOME_Container Cont_S 
+                                        -ORBInitRef NameService=IOR:01...
+     -> starts a Salome container called Cont_S connected to port 2810 
+        of xxx.cea.fr
+"""
+    parser = MyParser(usage=usage, epilog=epilog)
+    parser.add_option("-p", "--port", metavar="<port>", default="2810",
+                      action="store", type="string", dest="port",
+                      help="The port to connect to."
+                     )
+    parser.add_option("-m", "--machine", metavar="<machine>",
+                      action="store", type="string", dest="host", 
+                      default="localhost",
+                      help="The machine where salome was launched."
+                     )
+    parser.add_option('-d', '--directory', dest="directory", 
+                      metavar="<directory>", default=None,
+                      help="The directory where to execute the command."
+                     )
+
+    # separate runRemote args from the command to run (given after --)
+    short_args, extra_args = getShortAndExtraArgs(args)
+    try:
+      (options, args) = parser.parse_args(short_args)
+    except Exception as e:
+      print e
+      print usage
+      print epilog
+      return
+
+    port = options.port
+    host = options.host
+    directory = options.directory
+    command=extra_args[1:]
+
+    _writeConfigFile(port, host)
+    os.environ['NSPORT'] = port
+    os.environ['NSHOST'] = host
+    print("[ Remote Command ] ", " ".join(command))
+    cmd = subprocess.Popen(command, cwd=directory)
+    cmd.wait()
+    return
+#
+
index 85d132655b4552c9cb5ea0dd10e82f1ed5a00c6e..ae0267c9d78f6eb794f4d3a8f08f33a33fc24a22 100755 (executable)
@@ -45,6 +45,7 @@ Commands:
                     User works in a Shell terminal. SALOME environment is set but
                     application is not started.
     connect         Connect a Python console to the active SALOME instance.
+    remote          run command in SALOME environment from remote call, ssh or rsh.
     kill <port(s)>  Terminate SALOME instances running on given ports for current user.
                     Port numbers must be separated by blank characters.
     killall         Terminate *all* SALOME running instances for current user.
@@ -216,6 +217,7 @@ class SalomeContext:
       'start'   : '_runAppli',
       'context' : '_setContext',
       'shell'   : '_runSession',
+      'remote'  : '_runRemote',
       'connect' : '_runConsole',
       'kill'    : '_kill',
       'killall' : '_killAll',
@@ -362,6 +364,18 @@ class SalomeContext:
     return runSession.runSession(params, args)
   #
 
+  def _runRemote(self, args=None):
+    if args is None:
+      args = []
+#   complete salome environment 
+    sys.argv = ['runRemote']
+    import setenv
+    setenv.main(True)
+
+    import runRemote
+    return runRemote.runRemote(args)
+  #
+
   def _runConsole(self, args=None):
     if args is None:
       args = []