X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=doc%2Fbuild%2Fhtml%2Fwrite_command.html;h=ce276e2f0d5298fa63cec1b7982a0aef766a1fc3;hb=45d75d903722fdd81a492696ada9f37668d17753;hp=d5f0c6e646476886b6a6580a8164a7488795f763;hpb=a99a6f7bf7be23bb64bdd090ab709d14498449f4;p=tools%2Fsat.git diff --git a/doc/build/html/write_command.html b/doc/build/html/write_command.html index d5f0c6e..ce276e2 100644 --- a/doc/build/html/write_command.html +++ b/doc/build/html/write_command.html @@ -2,31 +2,20 @@ -
+ - -This documentation is for Python developers.
The salomeTools product provides a simple way to develop commands. -The first thing to do is to add a file with .py extension in the commands directory of salomeTools.
+The first thing to do is to add a file with .py extension in thecommands
directory of salomeTools.
Here are the basic requirements that must be followed in this file in order to add a command.
By adding a file mycommand.py in the commands directory, salomeTools will define a new command named mycommand.
+By adding a file mycommand.py in the commands
directory, salomeTools will define a new command named mycommand
.
In mycommand.py, there must be the following method:
-def run(args, runner, logger):
- # your algorithm ...
+def run(args, runner, logger):
+ # your algorithm ...
pass
@@ -70,38 +58,38 @@ But there are some useful services provided by salomeTools :
import src
+import src
-# Define all possible option for mycommand command : 'sat mycommand <options>'
+# Define all possible option for mycommand command : 'sat mycommand <options>'
parser = src.options.Options()
-parser.add_option('m', 'myoption', \
- 'boolean', 'myoption', \
- 'My option changes the behavior of my command.')
+parser.add_option('m', 'myoption', \
+ 'boolean', 'myoption', \
+ 'My option changes the behavior of my command.')
def run(args, runner, logger):
- # Parse the options
+ # Parse the options
(options, args) = parser.parse_args(args)
- # algorithm
+ # algorithm
import src
+ import src
- # Define all possible option for mycommand command : 'sat mycommand <options>'
+ # Define all possible option for mycommand command : 'sat mycommand <options>'
parser = src.options.Options()
- parser.add_option('m', 'myoption', \
- 'boolean', 'myoption', \
- 'My option changes the behavior of my command.')
+ parser.add_option('m', 'myoption', \
+ 'boolean', 'myoption', \
+ 'My option changes the behavior of my command.')
def description():
- return _("The help of mycommand.")
+ return _("The help of mycommand.")
def run(args, runner, logger):
- # Parse the options
+ # Parse the options
(options, args) = parser.parse_args(args)
- # algorithm
+ # algorithm
The runner variable gives also access to other commands of salomeTools:
-# as CLI_ 'sat prepare ...'
+# as CLI_ 'sat prepare ...'
runner.prepare(runner.cfg.VARS.application)
@@ -124,7 +112,7 @@ contains the root directory of the current application.
It gives access to the write method.
When this method is called, the message passed as parameter
will be displayed in the terminal and written in an xml log file.
-logger.write("My message", 3) # 3 as default
+logger.write("My message", 3) # 3 as default
The second argument defines the level of verbosity
@@ -134,7 +122,7 @@ It has to be between 1 and 5 (the most verbose level).
HELLO example¶
Here is a hello command, file commands/hello.py:
-import src
+import src
"""
hello.py
@@ -143,34 +131,34 @@ It has to be between 1 and 5 (the most verbose level).
"""
parser = src.options.Options()
-parser.add_option('f', 'french', 'boolean', 'french', "french set hello message in french.")
+parser.add_option('f', 'french', 'boolean', 'french', "french set hello message in french.")
def description():
- return _("The help of hello.")
+ return _("The help of hello.")
def run(args, runner, logger):
- # Parse the options
+ # Parse the options
(options, args) = parser.parse_args(args)
- # algorithm
+ # algorithm
if not options.french:
- logger.write('HELLO! WORLD!\n')
+ logger.write('HELLO! WORLD!\n')
else:
- logger.write('Bonjour tout le monde!\n')
+ logger.write('Bonjour tout le monde!\n')
A first call of hello:
-# Get the help of hello:
+# Get the help of hello:
./sat --help hello
-# To get bonjour
+# To get bonjour
./sat hello --french
Bonjour tout le monde!
-# To get hello
+# To get hello
./sat hello
HELLO! WORLD!
-# To get the log
+# To get the log
./sat log
@@ -181,7 +169,7 @@ HELLO! WORLD!
-