2 \page salome_command salome command
4 To start SALOME a new approach is proposed, based on \ref SALOME_Application. The underlying mechanism aims at:
5 -# Unifying start commands\n
6 Unix Shell scripts like runAppli, runSession and runConsole are replaced by a unique Python command named \b salome.
7 -# Handle execution context\n
8 After SALOME exit, environment is restored to its initial state. No Shell file sourcing is required; context management is achieved using Python standard API for context files parsing.
9 -# Promote creation of custom start commands (launchers)\n
10 A launcher is a Python script that creates an execution context then starts SALOME in this context. It uses methods provided by an Application Programming Interface (API). The \b salome command is a launcher. Several launchers may exist simultaneously; each uses the same API and focuses on execution context creation.
13 \section salome_launcher The salome command
14 Usage of \c salome command is:
16 salome [command] [options] [--config=<file,folder,...>]
21 Start a new SALOME instance.
23 Initialize SALOME context. Current environment is extended.
25 Initialize SALOME context, attached to the last created SALOME instance if any, and executes scripts passed as command arguments. User works in a Shell terminal; SALOME environment is set but application is not started.
27 Connect a Python console to the active SALOME instance.
28 - \c kill <port(s)> \n
29 Terminate SALOME instances running on given ports for current user. Port numbers must be separated by blank characters.
31 Terminate *all* SALOME running instances for current user ; do not start a new one.
35 Display some information about SALOME.
40 To start an application, use \code salome start \endcode
41 This command is equivalent to runAppli. It accepts the same options that can be listed using \code salome start --help \endcode
43 To initialize an environment, use \code salome shell \endcode
44 This command is equivalent to runSession. It accepts the same options that can be listed using \code salome shell --help \endcode
46 To connect a Python console, use \code salome connect \endcode
47 There is no options to this command. It asks user which SALOME instance to connect to.
49 \section context_files Context files management
50 The <tt>--config</tt> option is used to identify the list of configuration files or directories to be used for SALOME context creation. When this option is given, only files provided by user are considered. If user does not specify any context file SALOME will rely on context files detected in the env.d application folder. Two file formats can coexist, with a .cfg or .sh extension that are associated with the new and the former start mechanism, respectively.
52 The \c salome command is based on the .cfg format; however, it is able to interpret (partially) the .sh format for software backward compatibility. The use of .cfg format is highly recommended with the new launcher.
54 It is possible to add context files in the env.d folder; the strategy followed by \c salome
55 for these files is as follows. All files with .cfg extension are taken into account. Files with .sh extension are taken into account only if there is no file with the same name with
56 a .cfg extension, for example:
57 -# Context1.cfg : taken into account because it has a .cfg extension.
58 -# Context2.cfg : taken into account because it has a .cfg extension.
59 -# Context2.sh : not taken into account because Context2.cfg exists.
60 -# Context3.sh : considered because Context3.cfg does not exist.
62 Considered .sh files are automatically translated to .cfg format (the .cfg file is not written to disk). The translator is not as complete as Unix Shell interpreter; malfunctions may emerge in case of unrecognized syntax.
65 \section several_scripts_multiple_args Run several scripts with multiple arguments
66 On the one hand, runAppli options allow to give a list of Python scripts to be run after application startup; but it is not possible to specify parameters for these scripts. On the other hand runSession can run one script but it admits several parameters.
68 The \c salome command combines the two solutions: you can specify multiple scripts, each can have several parameters. For this, the following syntax must be used; to provide parameters to a script from the command line, we write <tt>script.py args: arg1, arg2, ..., argn</tt>
70 The script parameters must be separated by commas and no spaces are allowed (except
71 between the script name and the beginning of its parameters).
72 For example, the following call will run sequentially three scripts, which will wait 5 seconds, say hello, and calculate 1 +2 +3:
74 salome shell –p 2811 wait.py args:5 hello.py add.py args:1,2,3
77 The command \c salome \c shell allows a double dash syntax (- -) to indicate an extra command to be run "as is". It allows calling a extern program or system command having options and arguments that contain simple dash (-) characters.
78 The syntax is \code salome shell -- <program> [options] [arguments] \endcode
81 salome shell -- ls -l *.py
82 salome shell -- python -tt hello.py
85 \section handling_concurrency Handling concurrent starts
86 A SALOME instance uses a dedicated TCP port number on which the CORBA name server of each SALOME application will connect. This refers to a technical solution that allows multiple software components belonging to the same application to communicate with each other. This approach is a standard used when multiple applications are running at the same time (components should not interfere with each other), and when application components can be distributed across multiple machines.
88 Each SALOME application owns a specific port number. This port is determined automatically when application starts. When multiple applications are started at the same time, assigning a number to each port could be conflicting, and the same port could be assigned to several applications. To prevent from such a situation, a Python object named \c Portmanager has been implemented. This object has been introduced in SALOME 7 as an optional tool, then evaluated on Linux and Windows. In SALOME 8, this object becomes the standard.
90 Several instances can be safely started concurrently. For example in an automated process, calling several times the following commands (WORK_DIR variable changes at each call):
92 salome start -t --ns-port-log=${WORK_DIR}/session.log
93 salome shell -p `cat ${WORK_DIR}/session.log` ${SALOME_APPLI_FOLDER}/bin/salome/waitContainers.py # may be optional
94 salome shell -p `cat ${WORK_DIR}/session.log` ${BASE_DIR}/hello.py
95 salome kill `cat ${WORK_DIR}/session.log`
98 \section remote_calls Remote calls
99 With \c salome \c shell user can connect to a SALOME instance running on a remote computer. In this case the options <tt>-p PORT</tt>, <tt>-m MACHINE</tt>, <tt>-d DIRECTORY</tt> and <tt>-u USER</tt> must be provided. Moreover syntax <tt>out:res1,res2,...</tt> can be used to get results back from remote machine.
102 salome shell -m remotemachine -p 2810 -u myself -d /full/path/to/salome concatenate.py args:file1.txt,file2.txt out:result.txt
104 In this example user <tt>myself</tt> connects to <tt>remotemachine</tt> to run the script <tt>concatenate.py</tt> in a SALOME instance running on port <tt>2810</tt>; the script takes two input parameters and produces one result file.
105 The script and the input files are on the local computer. They are copied to the remote machine using a secure connection ; results produced on remote computer are transferred on the local machine using the same protocol. Script, input files and results are removed from remote machine.
108 \section write_launcher How to write a launcher
109 A launcher is a Python module that contains a single <tt>def main(args)</tt> function to sequentially execute the following operations:
110 - Detect application path
112 currentPath = os.path.dirname( os.path.abspath( __file__ ) )
113 launcherFile = os.path.basename(__file__)
114 from salome_starter import initialize
115 initialize(currentPath, launcherFile)
117 - Identify configuration (context) files
119 from salomeContextUtils import getConfigFileNames
120 configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True)
124 context = SalomeContext(configFileNames)
126 The execution context can be set or overloaded using \ref salome_api, for example:
128 # context.addToPath('mypath')
129 # context.addToLdLibraryPath('myldlibrarypath')
130 # context.addToPythonPath('mypythonpath')
131 # context.setVariable('myvarname', 'value')
135 (out, err), returncode = context.runSalome(args)
138 This module is generally used as a script, run from a shell command line. It thus contains the directive:
140 if __name__ == "__main__":
146 Finally the module can be called from another script, for example a test script. Considering a Python variable \c path_to_launcher that identifies the absolute path to a launcher, one can write:
148 appli_dir = os.path.dirname(path_to_launcher)
149 sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")]
150 self.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome"))
152 self.SALOME.main(["shell", "hello.py"])
153 except SystemExit, e:
159 \section salome_api The API
160 An API named \c SalomeContext, written in Python, allows for the construction of SALOME execution context and for application start. Each launcher creates a \c SalomeContext object, and optionally gives it a list of configuration files to describe the context:
162 SalomeContext.__init__(configFileNames=None)
165 A launcher can also directly call the API functions to define, suppress or extend (add information) an environment variable:
167 SalomeContext.setVariable(name, value, overwrite=False)
168 SalomeContext.unsetVariable(name)
169 SalomeContext.addToVariable(name, value, separator=os.pathsep)
172 The \c addToVariable function consists in prefixing the variable name with the given value inserting a separator between the two items.
174 Unix system variables PATH, LD_LIBRARY_PATH (DYLD_LIBRARY PATH for BSD) and PYTHONPATH can only be extended:
176 SalomeContext.addToPath(value)
177 SalomeContext.addToLdLibraryPath(value)
178 SalomeContext.addToDyldLibraryPath(value)
179 SalomeContext.addToPythonPath(value)
182 Once the context is created, the application is started:
184 SalomeContext.runSalome(args)
187 The \c args list corresponds to commands and options given to \c salome launcher.
190 \section context_file_syntax Syntax of a context file
191 It is possible to write specific context files provided that the syntax defined
192 hereinafter is respected; their analysis by the new SALOME start mechanism uses tools from the Python standard API.
194 A context file starts with a section title, and continues with the definition of different
195 context variables. The section title is a string enclosed by brackets, for example <tt>[My context]</tt>.
197 \subsection context_file_syntax_definition Definition
198 A variable can be defined with a declaration <tt>variable=value</tt>:
200 SALOME_PREREQUISITES=salome/prerequisites/install
203 \subsection context_file_syntax_substitution Substitution
204 A variable can be defined relative to another one; this substitution corresponds to the syntax <tt>%(variable)s</tt>:
206 QTDIR=${HOME}/%(SALOME_PREREQUISITES)s/Qt-484
208 In this example QTDIR will equal ${HOME}/salome/prerequisites/install/Qt-484
210 \subsection context_file_syntax_system System variables
211 Specific system variables such as PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH and PYTHONPATH are extended with <tt>ADD_TO_variable: valeur</tt>.
213 ADD_TO_PATH: %(QTDIR)s/bin
214 ADD_TO_LD_LIBRARY_PATH: %(QTDIR)s/lib
215 ADD_TO_PYTHONPATH: %(PYQT_ROOT_DIR)s/lib/python2.7/site-packages
218 \subsection context_file_syntax_unset Unset
219 A variable can be unset with <tt>UNSET: variable</tt>:
221 UNSET: LD_LIBRARY_PATH PTHREAD_ROOT_DIR