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,...>] [--extra_env=<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.
50 \section batch_files Batch files that set extra environment
51 The <tt>--extra_env</tt> option is used to identify a list of batch files (or directories containing such files) that must be considered to create the SALOME execution context. Typically on linux these files are shell scripts that modify the global environment. The salome command determines environment changes implied by running these files to initialize SALOME context. Note that this functionality is not the recommanded way to set SALOME context ; it is provided for backward compatibility and convenience ; prefer \ref context_files solution.
53 \section context_files Context files management
54 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.
56 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.
58 It is possible to add context files in the env.d folder; the strategy followed by \c salome
59 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
60 a .cfg extension, for example:
61 -# Context1.cfg : taken into account because it has a .cfg extension.
62 -# Context2.cfg : taken into account because it has a .cfg extension.
63 -# Context2.sh : not taken into account because Context2.cfg exists.
64 -# Context3.sh : considered because Context3.cfg does not exist.
66 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.
69 \section several_scripts_multiple_args Run several scripts with multiple arguments
70 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.
72 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>
74 The script parameters must be separated by commas and no spaces are allowed (except
75 between the script name and the beginning of its parameters).
76 For example, the following call will run sequentially three scripts, which will wait 5 seconds, say hello, and calculate 1 +2 +3:
78 salome shell –p 2811 wait.py args:5 hello.py add.py args:1,2,3
81 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.
82 The syntax is \code salome shell -- <program> [options] [arguments] \endcode
85 salome shell -- ls -l *.py
86 salome shell -- python -tt hello.py
89 \section handling_concurrency Handling concurrent starts
90 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.
92 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 (Linux only). In SALOME 7, this object is available when activating a specific compilation flag of KERNEL module:
93 - For gcc: -DWITH_PORTMANAGER
94 - With CMake: SALOME_USE_PORTMANAGER=ON
96 Since SALOME 7.5.0 this flag is switched ON by default.
97 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):
99 salome start -t --ns-port-log=${WORK_DIR}/session.log
100 salome shell -p `cat ${WORK_DIR}/session.log` ${SALOME_APPLI_FOLDER}/bin/salome/waitContainers.py # may be optional
101 salome shell -p `cat ${WORK_DIR}/session.log` ${BASE_DIR}/hello.py
102 salome kill `cat ${WORK_DIR}/session.log`
105 \section remote_calls Remote calls
106 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.
109 salome shell -m remotemachine -p 2810 -u myself -d /full/path/to/salome concatenate.py args:file1.txt,file2.txt out:result.txt
111 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.
112 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.
115 \section write_launcher How to write a launcher
116 A launcher is a Python module that contains a single <tt>def main(args)</tt> function to sequentially execute the following operations:
117 - Detect application path
119 currentPath = os.path.dirname( os.path.abspath( __file__ ) )
120 launcherFile = os.path.basename(__file__)
121 from salome_starter import initialize
122 initialize(currentPath, launcherFile)
124 - Identify configuration (context) files
126 from salomeContextUtils import getConfigFileNames
127 configFileNames, extraEnv, args, unexisting = getConfigFileNames(args, checkExistence=True)
132 context = SalomeContext(configFileNames)
134 The execution context can be set or overloaded using \ref salome_api, for example:
136 # context.addToPath('mypath')
137 # context.addToLdLibraryPath('myldlibrarypath')
138 # context.addToPythonPath('mypythonpath')
139 # context.setVariable('myvarname', 'value')
141 - Initializing extra environment variables parsed from batch files:
144 for key,val in extraEnv.items():
145 context.addToVariable(key,val)
149 (out, err), returncode = context.runSalome(args)
152 This module is generally used as a script, run from a shell command line. It thus contains the directive:
154 if __name__ == "__main__":
160 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:
162 appli_dir = os.path.dirname(path_to_launcher)
163 sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")]
164 self.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome"))
166 self.SALOME.main(["shell", "hello.py"])
167 except SystemExit, e:
173 \section salome_api The API
174 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:
176 SalomeContext.__init__(configFileNames=None)
179 A launcher can also directly call the API functions to define, suppress or extend (add information) an environment variable:
181 SalomeContext.setVariable(name, value, overwrite=False)
182 SalomeContext.unsetVariable(name)
183 SalomeContext.addToVariable(name, value, separator=os.pathsep)
186 The \c addToVariable function consists in prefixing the variable name with the given value inserting a separator between the two items.
188 Unix system variables PATH, LD_LIBRARY_PATH (DYLD_LIBRARY PATH for BSD) and PYTHONPATH can only be extended:
190 SalomeContext.addToPath(value)
191 SalomeContext.addToLdLibraryPath(value)
192 SalomeContext.addToDyldLibraryPath(value)
193 SalomeContext.addToPythonPath(value)
196 Once the context is created, the application is started:
198 SalomeContext.runSalome(args)
201 The \c args list corresponds to commands and options given to \c salome launcher.
204 \section context_file_syntax Syntax of a context file
205 It is possible to write specific context files provided that the syntax defined
206 hereinafter is respected; their analysis by the new SALOME start mechanism uses tools from the Python standard API.
208 A context file starts with a section title, and continues with the definition of different
209 context variables. The section title is a string enclosed by brackets, for example <tt>[My context]</tt>.
211 \subsection context_file_syntax_definition Definition
212 A variable can be defined with a declaration <tt>variable=value</tt>:
214 SALOME_PREREQUISITES=salome/prerequisites/install
217 \subsection context_file_syntax_substitution Substitution
218 A variable can be defined relative to another one; this substitution corresponds to the syntax <tt>%(variable)s</tt>:
220 QTDIR=${HOME}/%(SALOME_PREREQUISITES)s/Qt-484
222 In this example QTDIR will equal ${HOME}/salome/prerequisites/install/Qt-484
224 \subsection context_file_syntax_system System variables
225 Specific system variables such as PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH and PYTHONPATH are extended with <tt>ADD_TO_variable: valeur</tt>.
227 ADD_TO_PATH: %(QTDIR)s/bin
228 ADD_TO_LD_LIBRARY_PATH: %(QTDIR)s/lib
229 ADD_TO_PYTHONPATH: %(PYQT_ROOT_DIR)s/lib/python2.7/site-packages
232 \subsection context_file_syntax_unset Unset
233 A variable can be unset with <tt>UNSET: variable</tt>:
235 UNSET: LD_LIBRARY_PATH PTHREAD_ROOT_DIR