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=file1,...,filen]
20 -# \c start: start a new SALOME application. This is the default command.
21 -# \c shell: initialize SALOME environment, attached to the last created execution context if any. User works in a Shell terminal; SALOME environment is set but application is not started.
22 -# \c connect: connect a Python console to an active SALOME session.
23 -# \c killall: terminates all SALOME sessions (do not start a new one).
24 -# \c info: displays Python and SALOME versions.
25 -# \c help: obvious...
27 To start an application, use \code salome start \endcode
28 This command is equivalent to runAppli. It accepts the same options that can be listed using \code salome start --help \endcode
30 To initialize an environment, use \code salome shell \endcode
31 This command is equivalent to runSession. It accepts the same options that can be listed using \code salome shell --help \endcode
33 To connect a Python console, use \code salome connect \endcode
34 There is no options to this command. It asks user which SALOME session to connect to.
37 \section context_files Context files management
38 The <tt>--config</tt> option is used to identify the list of configuration files 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.
40 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.
42 It is possible to add context files in the env.d folder; the strategy followed by \c salome
43 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
44 a .cfg extension, for example:
45 -# Context1.cfg : taken into account because it has a .cfg extension.
46 -# Context2.cfg : taken into account because it has a .cfg extension.
47 -# Context2.sh : not taken into account because Context2.cfg exists.
48 -# Context3.sh : considered because Context3.cfg does not exist.
50 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.
53 \section new_features New features
54 \subsection new_features_scripts Run several scripts with multiple arguments
55 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.
57 The new \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>
59 The script parameters must be separated by commas and no spaces are allowed (except
60 between the script name and the beginning of its parameters).
61 For example, the following call will run sequentially three scripts, which will wait 5 seconds, say hello, and calculate 1 +2 +3:
63 salome shell –p 2811 wait.py args:5 hello.py add.py args:1,2,3
66 \subsection new_features_concurrency Handle concurrent starts
67 In the previous command, the <tt>-p</tt> option is used to specify a TCP port number on which the CORBA name server of each SALOME application will connect. In an attempt to explain it simply, we are talking about a technique 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.
69 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 may be conflicting, and the same port may be assigned to several applications. To resolve this situation, a Python object named \c Portmanager is proposed (Linux only). In SALOME 7, this object is available when activating a specific compilation flag of KERNEL module:
70 - For gcc: -DWITH_PORTMANAGER
71 - With CMake: SALOME_USE_PORTMANAGER=ON
74 \section write_launcher How to write a launcher
75 A launcher is a Python module that contains a single <tt>def main(args)</tt> function to sequentially execute the following operations:
76 - Detect application path
78 currentPath = os.path.dirname( os.path.abspath( __file__ ) )
79 launcherFile = os.path.basename(__file__)
80 from salome_starter import initialize
81 initialize(currentPath, launcherFile)
83 - Identify configuration (context) files
85 from salomeContextUtils import getConfigFileNames
86 configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True
90 context = SalomeContext(configFileNames)
94 (out, err), returncode = context.runSalome(args)
97 This module is generally used as a script, run from a shell command line. It thus contains the directive:
99 if __name__ == "__main__":
105 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:
107 appli_dir = os.path.dirname(path_to_launcher)
108 sys.path[:0] = [os.path.join(appli_dir, "bin", "salome", "appliskel")]
109 self.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome"))
111 self.SALOME.main(["shell", "hello.py"])
112 except SystemExit, e:
118 \section salome_api The API
119 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:
121 SalomeContext.__init__(configFileNames=None)
124 A launcher can also directly call the API functions to define, suppress or extend (add information) an environment variable:
126 SalomeContext.setVariable(name, value, overwrite=False)
127 SalomeContext.unsetVariable(name)
128 SalomeContext.addToVariable(name, value, separator=os.pathsep)
131 The \c addToVariable function consists in prefixing the variable name with the given value inserting a separator between the two items.
133 Unix system variables PATH, LD_LIBRARY_PATH (DYLD_LIBRARY PATH for BSD) and PYTHONPATH can only be extended:
135 SalomeContext.addToPath(value)
136 SalomeContext.addToLdLibraryPath(value)
137 SalomeContext.addToDyldLibraryPath(value)
138 SalomeContext.addToPythonPath(value)
141 Once the context is created, the application is started:
143 SalomeContext.runSalome(args)
146 The \c args list corresponds to commands and options given to \c salome launcher.
149 \section context_file_syntax Syntax of a context file
150 It is possible to write specific context files provided that the syntax defined
151 hereinafter is respected; their analysis by the new SALOME start mechanism uses tools from the Python standard API.
153 A context file starts with a section title, and continues with the definition of different
154 context variables. The section title is a string enclosed by brackets, for example <tt>[My context]</tt>.
156 \subsection context_file_syntax_definition Definition
157 A variable can be defined with a declaration <tt>variable=value</tt>:
159 SALOME_PREREQUISITES=salome/prerequisites/install
162 \subsection context_file_syntax_substitution Substitution
163 A variable can be defined relative to another one; this substitution corresponds to the syntax <tt>%(variable)s</tt>:
165 QTDIR=${HOME}/%(SALOME_PREREQUISITES)s/Qt-484
167 In this example QTDIR will equal ${HOME}/salome/prerequisites/install/Qt-484
169 \subsection context_file_syntax_system System variables
170 Specific system variables such as PATH, LD_LIBRARY_PATH, DYLD_LIBRARY_PATH and PYTHONPATH are extended with <tt>ADD_TO_variable: valeur</tt>.
172 ADD_TO_PATH: %(QTDIR)s/bin
173 ADD_TO_LD_LIBRARY_PATH: %(QTDIR)s/lib
174 ADD_TO_PYTHONPATH: %(PYQT_ROOT_DIR)s/lib/python2.7/site-packages
177 \subsection context_file_syntax_unset Unset
178 A variable can be unset with <tt>UNSET: variable</tt>:
180 UNSET: LD_LIBRARY_PATH PTHREAD_ROOT_DIR