From 47c5478b98254f5688c4cf85d37eac127fd30b0a Mon Sep 17 00:00:00 2001 From: crouzet Date: Wed, 5 Dec 2018 10:25:20 +0100 Subject: [PATCH] add runRemote command to salome launcher --- bin/CMakeLists.txt | 1 + bin/runRemote.py | 101 +++++++++++++++++++++++++++++++++++++++++++ bin/salomeContext.py | 14 ++++++ 3 files changed, 116 insertions(+) create mode 100644 bin/runRemote.py diff --git a/bin/CMakeLists.txt b/bin/CMakeLists.txt index 311ae399a..bba6cb6d8 100644 --- a/bin/CMakeLists.txt +++ b/bin/CMakeLists.txt @@ -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 index 000000000..376f6a66c --- /dev/null +++ b/bin/runRemote.py @@ -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="", default="2810", + action="store", type="string", dest="port", + help="The port to connect to." + ) + parser.add_option("-m", "--machine", metavar="", + action="store", type="string", dest="host", + default="localhost", + help="The machine where salome was launched." + ) + parser.add_option('-d', '--directory', dest="directory", + metavar="", 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 +# + diff --git a/bin/salomeContext.py b/bin/salomeContext.py index 85d132655..ae0267c9d 100755 --- a/bin/salomeContext.py +++ b/bin/salomeContext.py @@ -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 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 = [] -- 2.39.2