Salome HOME
Synchronize adm files
[modules/kernel.git] / doc / salome / salome_command.dox
1 /*!
2   \page salome_command salome command
3
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.
11
12
13 \section salome_launcher The salome command
14 Usage of \c salome command is:
15 \code
16    salome [command] [options] [--config=file1,...,filen]
17 \endcode
18
19 Commands are:
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...
26
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
29
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
32
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.
35
36
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.
39
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.
41
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.
49
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.
51
52
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.
56
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>
58
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:
62 \code
63 salome shell –p 2811 wait.py args:5 hello.py add.py args:1,2,3
64 \endcode
65
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.
68
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
72
73
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
77 \code
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)
82 \endcode
83 - Identify configuration (context) files
84 \code
85 from salomeContextUtils import getConfigFileNames
86 configFileNames, args, unexisting = getConfigFileNames(args, checkExistence=True
87 \endcode
88 - Create a context
89 \code
90 context = SalomeContext(configFileNames)
91 \endcode
92 - Run SALOME
93 \code
94 (out, err), returncode = context.runSalome(args)
95 \endcode
96
97 This module is generally used as a script, run from a shell command line. It thus contains the directive:
98 \code
99 if __name__ == "__main__":
100   args = sys.argv[1:]
101   main(args)
102 #
103 \endcode
104
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:
106 \code
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"))
110 try:
111   self.SALOME.main(["shell", "hello.py"])
112 except SystemExit, e:
113   if str(e) != '0':
114     logging.error(e)
115 \endcode
116
117
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:
120 \code
121 SalomeContext.__init__(configFileNames=[])
122 \endcode
123
124 A launcher can also directly call the API functions to define, suppress or extend (add information) an environment variable:
125 \code
126 SalomeContext.setVariable(name, value, overwrite=False)
127 SalomeContext.unsetVariable(name)
128 SalomeContext.addToVariable(name, value, separator=os.pathsep)
129 \endcode
130
131 The \c addToVariable function consists in prefixing the variable name with the given value inserting a separator between the two items.
132
133 Unix system variables PATH, LD_LIBRARY_PATH (DYLD_LIBRARY PATH for BSD) and PYTHONPATH can only be extended:
134 \code
135 SalomeContext.addToPath(value)
136 SalomeContext.addToLdLibraryPath(value)
137 SalomeContext.addToDyldLibraryPath(value)
138 SalomeContext.addToPythonPath(value)
139 \endcode
140
141 Once the context is created, the application is started:
142 \code
143 SalomeContext.runSalome(args)
144 \endcode
145
146 The \c args list corresponds to commands and options given to \c salome launcher.
147
148
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.
152
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>.
155
156 \subsection context_file_syntax_definition Definition
157 A variable can be defined with a declaration <tt>variable=value</tt>:
158 \code
159 SALOME_PREREQUISITES=salome/prerequisites/install
160 \endcode
161
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>:
164 \code
165 QTDIR=${HOME}/%(SALOME_PREREQUISITES)s/Qt-484
166 \endcode
167 In this example QTDIR will equal ${HOME}/salome/prerequisites/install/Qt-484
168
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>.
171 \code
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
175 \endcode
176
177 \subsection context_file_syntax_unset Unset
178 A variable can be unset with <tt>UNSET: variable</tt>:
179 \code
180 UNSET: LD_LIBRARY_PATH PTHREAD_ROOT_DIR
181 \endcode
182
183 \n
184
185 */