Salome HOME
small corrections
[tools/sat.git] / src / fileEnviron.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2013  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import os
20 import pprint as PP
21 import src.debug as DBG
22 import src.architecture
23 import src.environment
24
25 def get_file_environ(output, shell, environ=None):
26     """Instantiate correct FileEnvironment sub-class.
27     
28     :param output file: the output file stream.
29     :param shell str: the type of shell syntax to use.
30     :param environ dict: a potential additional environment.
31     """
32     if environ == None:
33         environ=src.environment.Environ({})
34     if shell == "bash":
35         return BashFileEnviron(output, environ)
36     if shell == "bat":
37         return BatFileEnviron(output, environ)
38     if shell == "cfgForPy":
39         return LauncherFileEnviron(output, environ)
40     if shell == "cfg":
41         return ContextFileEnviron(output, environ)
42     raise Exception("FileEnviron: Unknown shell = %s" % shell)
43
44 class FileEnviron(object):
45     """\
46     Base class for shell environment
47     """
48     def __init__(self, output, environ=None):
49         """\
50         Initialization
51         
52         :param output file: the output file stream.
53         :param environ dict: SalomeEnviron.
54         """
55         self._do_init(output, environ)
56
57     def __repr__(self):
58         """\
59         easy non exhaustive quick resume for debug print"""
60         res = {
61           "output" : self.output,
62           "environ" : self.environ,
63         }
64         return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(res))
65         
66
67     def _do_init(self, output, environ=None):
68         """\
69         Initialization
70         
71         :param output file: the output file stream.
72         :param environ dict: a potential additional environment.
73         """
74         self.output = output
75         self.init_path=True # by default we initialise all paths, except PATH
76         if environ is not None:
77             self.environ = environ
78         else:
79             self.environ = src.environment.Environ({})
80
81     def add_line(self, number):
82         """\
83         Add some empty lines in the shell file
84         
85         :param number int: the number of lines to add
86         """
87         self.output.write("\n" * number)
88
89     def add_comment(self, comment):
90         """\
91         Add a comment in the shell file
92         
93         :param comment str: the comment to add
94         """
95         self.output.write("# %s\n" % comment)
96
97     def add_echo(self, text):
98         """\
99         Add a "echo" in the shell file
100         
101         :param text str: the text to echo
102         """
103         self.output.write('echo %s"\n' % text)
104
105     def add_warning(self, warning):
106         """\
107         Add a warning "echo" in the shell file
108         
109         :param warning str: the text to echo
110         """
111         self.output.write('echo "WARNING %s"\n' % warning)
112
113     def append_value(self, key, value, sep=os.pathsep):
114         """\
115         append value to key using sep,
116         if value contains ":" or ";" then raise error
117
118         :param key str: the environment variable to append
119         :param value str: the value to append to key
120         :param sep str: the separator string
121         """
122         # check that value so no contain the system separator
123         separator=os.pathsep
124         if separator in value:
125             raise Exception("FileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
126         do_append=True
127         if self.environ.is_defined(key):
128             value_list = self.environ.get(key).split(sep)
129             if self.environ._expandvars(value) in value_list:
130                 do_append=False  # value is already in key path : we don't append it again
131             
132         if do_append:
133             self.environ.append_value(key, value,sep)
134             self.set(key, self.get(key) + sep + value)
135
136     def append(self, key, value, sep=os.pathsep):
137         """\
138         Same as append_value but the value argument can be a list
139         
140         :param key str: the environment variable to append
141         :param value str or list: the value(s) to append to key
142         :param sep str: the separator string
143         """
144         if isinstance(value, list):
145             for v in value:
146                 self.append_value(key, v, sep)
147         else:
148             self.append_value(key, value, sep)
149
150     def prepend_value(self, key, value, sep=os.pathsep):
151         """\
152         prepend value to key using sep,
153         if value contains ":" or ";" then raise error
154         
155         :param key str: the environment variable to prepend
156         :param value str: the value to prepend to key
157         :param sep str: the separator string
158         """
159         # check that value so no contain the system separator
160         separator=os.pathsep
161         if separator in value:
162             raise Exception("FileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
163
164         do_not_prepend=False
165         if self.environ.is_defined(key):
166             value_list = self.environ.get(key).split(sep)
167             exp_val=self.environ._expandvars(value)
168             if exp_val in value_list:
169                 do_not_prepend=True
170         if not do_not_prepend:
171             self.environ.prepend_value(key, value,sep)
172             self.set(key, value + sep + self.get(key))
173
174     def prepend(self, key, value, sep=os.pathsep):
175         """\
176         Same as prepend_value but the value argument can be a list
177         
178         :param key str: the environment variable to prepend
179         :param value str or list: the value(s) to prepend to key
180         :param sep str: the separator string
181         """
182         if isinstance(value, list):
183             for v in reversed(value): # prepend list, first item at last to stay first
184                 self.prepend_value(key, v, sep)
185         else:
186             self.prepend_value(key, value, sep)
187
188     def is_defined(self, key):
189         """\
190         Check if the key exists in the environment
191         
192         :param key str: the environment variable to check
193         """
194         return self.environ.is_defined(key)
195
196     def set(self, key, value):
197         """\
198         Set the environment variable 'key' to value 'value'
199         
200         :param key str: the environment variable to set
201         :param value str: the value
202         """
203         raise NotImplementedError("set is not implement for this shell!")
204
205     def get(self, key):
206         """\
207         Get the value of the environment variable "key"
208         
209         :param key str: the environment variable
210         """
211         return '${%s}' % key
212
213     def get_value(self, key):
214         """Get the real value of the environment variable "key"
215         It can help env scripts
216         :param key str: the environment variable
217         """
218         return self.environ.get_value(key)
219
220     def finish(self):
221         """Add a final instruction in the out file (in case of file generation)
222         
223         :param required bool: Do nothing if required is False
224         """
225         return
226
227     def set_no_init_path(self):
228         """Set the no initialisation mode for all paths.
229            By default only PATH is not reinitialised. All others paths are
230            (LD_LIBRARY_PATH, PYTHONPATH, ...)
231            After the call to these function ALL PATHS ARE NOT REINITIALISED.
232            There initial value is inherited from the environment
233         """
234         self.init_path=False
235
236     def value_filter(self, value):
237         res=value
238         # on windows platform, replace / by \
239         if src.architecture.is_windows():
240             res = value.replace("/","\\")
241         return res
242
243
244 class BashFileEnviron(FileEnviron):
245     """\
246     Class for bash shell.
247     """
248     def __init__(self, output, environ=None):
249         """Initialization
250         
251         :param output file: the output file stream.
252         :param environ dict: a potential additional environment.
253         """
254         self._do_init(output, environ)
255         self.output.write(bash_header)
256
257     def set(self, key, value):
258         """Set the environment variable "key" to value "value"
259         
260         :param key str: the environment variable to set
261         :param value str: the value
262         """
263         self.output.write('export %s="%s"\n' % (key, value))
264         self.environ.set(key, value)
265         
266
267         
268 class BatFileEnviron(FileEnviron):
269     """\
270     for Windows batch shell.
271     """
272     def __init__(self, output, environ=None):
273         """Initialization
274         
275         :param output file: the output file stream.
276         :param environ dict: a potential additional environment.
277         """
278         self._do_init(output, environ)
279         self.output.write(bat_header)
280
281     def add_comment(self, comment):
282         """Add a comment in the shell file
283         
284         :param comment str: the comment to add
285         """
286         self.output.write("rem %s\n" % comment)
287     
288     def get(self, key):
289         """Get the value of the environment variable "key"
290         
291         :param key str: the environment variable
292         """
293         return '%%%s%%' % key
294     
295     def set(self, key, value):
296         """Set the environment variable "key" to value "value"
297         
298         :param key str: the environment variable to set
299         :param value str: the value
300         """
301         self.output.write('set %s=%s\n' % (key, self.value_filter(value)))
302         self.environ.set(key, value)
303
304
305 class ContextFileEnviron(FileEnviron):
306     """Class for a salome context configuration file.
307     """
308     def __init__(self, output, environ=None):
309         """Initialization
310         
311         :param output file: the output file stream.
312         :param environ dict: a potential additional environment.
313         """
314         self._do_init(output, environ)
315         self.output.write(cfg_header)
316
317     def set(self, key, value):
318         """Set the environment variable "key" to value "value"
319         
320         :param key str: the environment variable to set
321         :param value str: the value
322         """
323         self.output.write('%s="%s"\n' % (key, value))
324         self.environ.set(key, value)
325
326     def get(self, key):
327         """Get the value of the environment variable "key"
328         
329         :param key str: the environment variable
330         """
331         return '%({0})s'.format(key)
332
333     def add_echo(self, text):
334         """Add a comment
335         
336         :param text str: the comment to add
337         """
338         self.add_comment(text)
339
340     def add_warning(self, warning):
341         """Add a warning
342         
343         :param text str: the warning to add
344         """
345         self.add_comment("WARNING %s"  % warning)
346
347     def prepend_value(self, key, value, sep=os.pathsep):
348         """prepend value to key using sep
349         
350         :param key str: the environment variable to prepend
351         :param value str: the value to prepend to key
352         :param sep str: the separator string
353         """
354         do_append=True
355         if self.environ.is_defined(key):
356             value_list = self.environ.get(key).split(sep)
357             #value cannot be expanded (unlike bash/bat case) - but it doesn't matter.
358             if value in value_list:
359                 do_append=False  # value is already in key path : we don't append it again
360             
361         if do_append:
362             self.environ.append_value(key, value,sep)
363             self.output.write('ADD_TO_%s: %s\n' % (key, value))
364
365     def append_value(self, key, value, sep=os.pathsep):
366         """append value to key using sep
367         
368         :param key str: the environment variable to append
369         :param value str: the value to append to key
370         :param sep str: the separator string
371         """
372         self.prepend_value(key, value)
373
374
375 class LauncherFileEnviron(FileEnviron):
376     """\
377     Class to generate a launcher file script 
378     (in python syntax) SalomeContext API
379     """
380     def __init__(self, output, environ=None):
381         """Initialization
382         
383         :param output file: the output file stream.
384         :param environ dict: a potential additional environment.
385         """
386         self._do_init(output, environ)
387         self.python_version=self.environ.get("sat_python_version")
388         self.bin_kernel_root_dir=self.environ.get("sat_bin_kernel_install_dir")
389         self.app_root_dir=self.environ.get("sat_app_root_dir")
390
391         # four whitespaces for first indentation in a python script
392         self.indent="    "
393         self.prefix="context."
394         self.setVarEnv="setVariable"
395         self.begin=self.indent+self.prefix
396
397         # write the begining of launcher file.
398         # choose the template version corresponding to python version 
399         # and substitute BIN_KERNEL_INSTALL_DIR (the path to salomeContext.py)
400         if self.python_version == 2:
401             launcher_header=launcher_header2
402         else:
403             launcher_header=launcher_header3
404         self.output.write(launcher_header\
405                           .replace("BIN_KERNEL_INSTALL_DIR", self.bin_kernel_root_dir))
406
407         # for these path, we use specialired functions in salomeContext api
408         self.specialKeys={"PATH": "Path",
409                           "LD_LIBRARY_PATH": "LdLibraryPath",
410                           "PYTHONPATH": "PythonPath"}
411
412         # we do not want to reinitialise PATH.
413         # for that we make sure PATH is in self.environ
414         # and therefore we will not use setVariable for PATH
415         if not self.environ.is_defined("PATH"):
416             self.environ.set("PATH","")
417
418
419     def add_echo(self, text):
420         """Add a comment
421         
422         :param text str: the comment to add
423         """
424         self.output.write('# %s"\n' % text)
425
426     def add_warning(self, warning):
427         """Add a warning
428         
429         :param text str: the warning to add
430         """
431         self.output.write('# "WARNING %s"\n' % warning)
432
433     def append_value(self, key, value, sep=":"):
434         """append value to key using sep,
435         if value contains ":" or ";" then raise error
436         
437         :param key str: the environment variable to append
438         :param value str: the value to append to key
439         :param sep str: the separator string
440         """
441         # append is not defined in context api
442         self.prepend_value(key, value)
443
444     def append(self, key, value, sep=":"):
445         """Same as append_value but the value argument can be a list
446         
447         :param key str: the environment variable to append
448         :param value str or list: the value(s) to append to key
449         :param sep str: the separator string
450         """
451         if isinstance(value, list):
452             for v in value:
453                 self.append_value(key, v, sep)
454         else:
455             self.append_value(key, value, sep)
456
457     def prepend_value(self, key, value, sep=os.pathsep):
458         """prepend value to key using sep,
459         if value contains ":" or ";" then raise error
460         
461         :param key str: the environment variable to prepend
462         :param value str: the value to prepend to key
463         :param sep str: the separator string
464         """
465         # check that value so no contain the system separator
466         separator=os.pathsep
467         msg="LauncherFileEnviron append key '%s' value '%s' contains forbidden character '%s'"
468         if separator in value:
469             raise Exception(msg % (key, value, separator))
470
471         if (self.init_path and (not self.environ.is_defined(key))):
472             # reinitialisation mode set to true (the default)
473             # for the first occurrence of key, we set it.
474             # therefore key will not be inherited from environment
475             self.set(key, value)
476             return
477         # in all other cases we use append (except if value is already the key
478         do_append=True
479         if self.environ.is_defined(key):
480             value_list = self.environ.get(key).split(sep)
481             # rem : value cannot be expanded (unlike bash/bat case) - but it doesn't matter.
482             if value in value_list:
483                 do_append=False  # value is already in key path : we don't append it again
484             
485         if do_append:
486             self.environ.append_value(key, value,sep) # register value in self.environ
487             if key in self.specialKeys.keys():
488                 #for these special keys we use the specific salomeContext function
489                 self.output.write(self.begin+'addTo%s(r"%s")\n' % 
490                                   (self.specialKeys[key], self.value_filter(value)))
491             else:
492                 # else we use the general salomeContext addToVariable function
493                 self.output.write(self.begin+'addToVariable(r"%s", r"%s",separator="%s")\n' 
494                                   % (key, self.value_filter(value), sep))
495             
496
497     def prepend(self, key, value, sep=":"):
498         """Same as prepend_value but the value argument can be a list
499         
500         :param key str: the environment variable to prepend
501         :param value str or list: the value(s) to prepend to key
502         :param sep str: the separator string
503         """
504         if isinstance(value, list):
505             for v in value:
506                 self.prepend_value(key, v, sep)
507         else:
508             self.prepend_value(key, value, sep)
509
510
511     def set(self, key, value):
512         """Set the environment variable "key" to value "value"
513         
514         :param key str: the environment variable to set
515         :param value str: the value
516         """
517         self.output.write(self.begin+self.setVarEnv+
518                           '(r"%s", r"%s", overwrite=True)\n' % 
519                           (key, self.value_filter(value)))
520         self.environ.set(key,value)
521     
522
523     def add_comment(self, comment):
524         # Special comment in case of the distène licence
525         if comment=="DISTENE license":
526             self.output.write(self.indent+
527                               "#"+
528                               self.prefix+
529                               self.setVarEnv+
530                               '(r"%s", r"%s", overwrite=True)\n' % 
531                               ('DISTENE_LICENSE_FILE', 'Use global envvar: DLIM8VAR'))
532             self.output.write(self.indent+
533                               "#"+
534                               self.prefix+
535                               self.setVarEnv+
536                               '(r"%s", r"%s", overwrite=True)\n' % 
537                               ('DLIM8VAR', '<your licence>'))
538             return
539         if "setting environ for" in comment:
540             self.output.write(self.indent+"#[%s]\n" % 
541                               comment.split("setting environ for ")[1])
542             return
543
544         self.output.write(self.indent+"# %s\n" % comment)
545
546     def finish(self):
547         """\
548         Add a final instruction in the out file (in case of file generation)
549         In the particular launcher case, do nothing
550         
551         :param required bool: Do nothing if required is False
552         """
553         if self.python_version == 2:
554             launcher_tail=launcher_tail_py2
555         else:
556             launcher_tail=launcher_tail_py3
557         self.output.write(launcher_tail)
558         return
559
560 class ScreenEnviron(FileEnviron):
561     def __init__(self, output, environ=None):
562         self._do_init(output, environ)
563         self.defined = {}
564
565     def add_line(self, number):
566         pass
567
568     def add_comment(self, comment):
569         pass
570
571     def add_echo(self, text):
572         pass
573
574     def add_warning(self, warning):
575         pass
576
577     def write(self, command, name, value, sign="="):
578         import src
579         self.output.write("  %s%s %s %s %s\n" % \
580             (src.printcolors.printcLabel(command),
581              " " * (12 - len(command)),
582              src.printcolors.printcInfo(name), sign, value))
583
584     def is_defined(self, name):
585         return name in self.defined
586
587     def get(self, name):
588         return "${%s}" % name
589
590     def set(self, name, value):
591         self.write("set", name, value)
592         self.defined[name] = value
593
594     def prepend(self, name, value, sep=":"):
595         if isinstance(value, list):
596             value = sep.join(value)
597         value = value + sep + self.get(name)
598         self.write("prepend", name, value)
599
600     def append(self, name, value, sep=":"):
601         if isinstance(value, list):
602             value = sep.join(value)
603         value = self.get(name) + sep + value
604         self.write("append", name, value)
605
606     def run_env_script(self, module, script):
607         self.write("load", script, "", sign="")
608
609
610 #
611 #  Headers
612 #
613 bat_header="""\
614 @echo off
615
616 rem The following variables are used only in case of a sat package
617 set out_dir_Path=%~dp0
618 """
619
620
621 bash_header="""\
622 #!/bin/bash
623 ##########################################################################
624 #
625 # This line is used only in case of a sat package
626 export out_dir_Path=$(cd $(dirname ${BASH_SOURCE[0]});pwd)
627
628 ###########################################################################
629 """
630
631 cfg_header="""\
632 [SALOME Configuration]
633 """
634
635 launcher_header2="""\
636 #! /usr/bin/env python
637
638 ################################################################
639 # WARNING: this file is automatically generated by SalomeTools #
640 # WARNING: and so could be overwritten at any time.            #
641 ################################################################
642
643 import os
644 import sys
645 import subprocess
646
647
648 # Add the pwdPath to able to run the launcher after unpacking a package
649 # Used only in case of a salomeTools package
650 out_dir_Path=os.path.dirname(os.path.realpath(__file__))
651
652 # Preliminary work to initialize path to SALOME Python modules
653 def __initialize():
654
655   sys.path[:0] = [ 'BIN_KERNEL_INSTALL_DIR' ]  # to get salomeContext
656   
657   # define folder to store omniorb config (initially in virtual application folder)
658   try:
659     from salomeContextUtils import setOmniOrbUserPath
660     setOmniOrbUserPath()
661   except Exception as e:
662     print(e)
663     sys.exit(1)
664 # End of preliminary work
665
666 # salome doc only works for virtual applications. Therefore we overwrite it with this function
667 def _showDoc(modules):
668     for module in modules:
669       modulePath = os.getenv(module+"_ROOT_DIR")
670       if modulePath != None:
671         baseDir = os.path.join(modulePath, "share", "doc", "salome")
672         docfile = os.path.join(baseDir, "gui", module.upper(), "index.html")
673         if not os.path.isfile(docfile):
674           docfile = os.path.join(baseDir, "tui", module.upper(), "index.html")
675         if not os.path.isfile(docfile):
676           docfile = os.path.join(baseDir, "dev", module.upper(), "index.html")
677         if os.path.isfile(docfile):
678           out, err = subprocess.Popen(["xdg-open", docfile]).communicate()
679         else:
680           print ("Online documentation is not accessible for module:", module)
681       else:
682         print (module+"_ROOT_DIR not found!")
683
684 def main(args):
685   # Identify application path then locate configuration files
686   __initialize()
687
688   if args == ['--help']:
689     from salomeContext import usage
690     usage()
691     sys.exit(0)
692
693
694   # Create a SalomeContext which parses configFileNames to initialize environment
695   try:
696     from salomeContext import SalomeContext, SalomeContextException
697     context = SalomeContext(None)
698     
699     # Here set specific variables, if needed
700     # context.addToPath('mypath')
701     # context.addToLdLibraryPath('myldlibrarypath')
702     # context.addToPythonPath('mypythonpath')
703     # context.setVariable('myvarname', 'value')
704
705     # Logger level error
706     context.getLogger().setLevel(40)
707 """
708
709 launcher_header3="""\
710 #! /usr/bin/env python3
711
712 ################################################################
713 # WARNING: this file is automatically generated by SalomeTools #
714 # WARNING: and so could be overwritten at any time.            #
715 ################################################################
716
717 import os
718 import sys
719 import subprocess
720
721
722 # Add the pwdPath to able to run the launcher after unpacking a package
723 # Used only in case of a salomeTools package
724 out_dir_Path=os.path.dirname(os.path.realpath(__file__))
725
726 # Preliminary work to initialize path to SALOME Python modules
727 def __initialize():
728
729   sys.path[:0] = [ 'BIN_KERNEL_INSTALL_DIR' ]
730   
731   # define folder to store omniorb config (initially in virtual application folder)
732   try:
733     from salomeContextUtils import setOmniOrbUserPath
734     setOmniOrbUserPath()
735   except Exception as e:
736     print(e)
737     sys.exit(1)
738 # End of preliminary work
739
740 # salome doc only works for virtual applications. Therefore we overwrite it with this function
741 def _showDoc(modules):
742     for module in modules:
743       modulePath = os.getenv(module+"_ROOT_DIR")
744       if modulePath != None:
745         baseDir = os.path.join(modulePath, "share", "doc", "salome")
746         docfile = os.path.join(baseDir, "gui", module.upper(), "index.html")
747         if not os.path.isfile(docfile):
748           docfile = os.path.join(baseDir, "tui", module.upper(), "index.html")
749         if not os.path.isfile(docfile):
750           docfile = os.path.join(baseDir, "dev", module.upper(), "index.html")
751         if os.path.isfile(docfile):
752           out, err = subprocess.Popen(["xdg-open", docfile]).communicate()
753         else:
754           print("Online documentation is not accessible for module:", module)
755       else:
756         print(module+"_ROOT_DIR not found!")
757
758 def main(args):
759   # Identify application path then locate configuration files
760   __initialize()
761
762   if args == ['--help']:
763     from salomeContext import usage
764     usage()
765     sys.exit(0)
766
767   #from salomeContextUtils import getConfigFileNames
768   #configFileNames, args, unexisting = getConfigFileNames( args, checkExistence=True )
769   #if len(unexisting) > 0:
770   #  print("ERROR: unexisting configuration file(s): " + ', '.join(unexisting))
771   #  sys.exit(1)
772
773   # Create a SalomeContext which parses configFileNames to initialize environment
774   try:
775     from salomeContext import SalomeContext, SalomeContextException
776     context = SalomeContext(None)
777     
778     # Here set specific variables, if needed
779     # context.addToPath('mypath')
780     # context.addToLdLibraryPath('myldlibrarypath')
781     # context.addToPythonPath('mypythonpath')
782     # context.setVariable('myvarname', 'value')
783
784     # Logger level error
785     context.getLogger().setLevel(40)
786 """
787
788 launcher_tail_py2="""\
789     if len(args) >1 and args[0]=='doc':
790         _showDoc(args[1:])
791         return
792
793     # Start SALOME, parsing command line arguments
794     out, err, status = context.runSalome(args)
795     sys.exit(status)
796
797   except SalomeContextException, e:
798     import logging
799     logging.getLogger("salome").error(e)
800     sys.exit(1)
801 #
802
803 if __name__ == "__main__":
804   args = sys.argv[1:]
805   main(args)
806 #
807 """
808
809 launcher_tail_py3="""\
810     if len(args) >1 and args[0]=='doc':
811         _showDoc(args[1:])
812         return
813
814     # Start SALOME, parsing command line arguments
815     out, err, status = context.runSalome(args)
816     sys.exit(status)
817
818   except SalomeContextException as e:
819     import logging
820     logging.getLogger("salome").error(e)
821     sys.exit(1)
822 #
823
824 if __name__ == "__main__":
825   args = sys.argv[1:]
826   main(args)
827 #
828 """
829     
830