1 # Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 from optparse import OptionParser
26 from salome_utils import getUserName
27 from salomeContextUtils import getShortAndExtraArgs
29 # Use to display newlines (\n) in epilog
30 class MyParser(OptionParser):
31 def format_epilog(self, formatter):
35 # --- set the OMNIORB_CONFIG file and environment relative to this run of SALOME
36 def _writeConfigFile(port, host):
37 path = os.environ['OMNIORB_USER_PATH']
38 kwargs = {'with_username' : getUserName()}
40 from ORBConfigFile import writeORBConfigFile
41 [ filename, msgSize ] = writeORBConfigFile(path, host, port, kwargs)
43 os.environ['OMNIORB_CONFIG'] = filename
49 usage = "Usage: salome runremote [options] -- command"
51 Execute command in SALOME environment from a remote call, ssh or rsh.
52 salome runremote is used notably to launch containers from a distant salome session.
55 salome remote -m xxx.cea.fr -p 2810 -- ls /tmp >/dev/null 2>&1
56 -> execute the command ls /tmp >/dev/null 2>&1
58 salome remote -m xxx.cea.fr -p 2810 -- SALOME_Container Cont_S
59 -ORBInitRef NameService=IOR:01...
60 -> starts a Salome container called Cont_S connected to port 2810
63 parser = MyParser(usage=usage, epilog=epilog)
64 parser.add_option("-p", "--port", metavar="<port>", default="2810",
65 action="store", type="string", dest="port",
66 help="The port to connect to."
68 parser.add_option("-m", "--machine", metavar="<machine>",
69 action="store", type="string", dest="host",
71 help="The machine where salome was launched."
73 parser.add_option('-d', '--directory', dest="directory",
74 metavar="<directory>", default=None,
75 help="The directory where to execute the command."
78 # separate runRemote args from the command to run (given after --)
79 short_args, extra_args = getShortAndExtraArgs(args)
81 (options, args) = parser.parse_args(short_args)
82 except Exception as e:
90 directory = options.directory
91 command=extra_args[1:]
93 _writeConfigFile(port, host)
94 os.environ['NSPORT'] = port
95 os.environ['NSHOST'] = host
96 print("[ Remote Command ] ", " ".join(command))
97 cmd = subprocess.Popen(command, cwd=directory)