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