3 # Copyright (C) 2010-2013 CEA/DEN
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.
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.
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
21 import src.debug as DBG
22 import src.architecture
23 import src.environment
28 rem The following variables are used only in case of a sat package
29 set out_dir_Path=%~dp0
35 ##########################################################################
38 # cleanup a path (first parameter) from duplicated entries;
39 # second parameter is the separator
41 out_var=`echo $1 | awk -v sep=$2 '{ \\
42 na = split($1,a,sep); \\
44 for(i=0;i<=na;i++) { \\
61 }' | sed -e 's|\\(.*\\)$1|\\1|g' -e 's|^[:;]||' -e 's|[:;]$||'`
68 out_var=`cleandup $xenv $2`
72 # This line is used only in case of a sat package
73 export out_dir_Path=$(cd $(dirname ${BASH_SOURCE[0]});pwd)
75 ###########################################################################
79 [SALOME Configuration]
83 # a generated SALOME Configuration file using python syntax
86 def get_file_environ(output, shell, environ=None):
87 """Instantiate correct FileEnvironment sub-class.
89 :param output file: the output file stream.
90 :param shell str: the type of shell syntax to use.
91 :param environ dict: a potential additional environment.
94 return BashFileEnviron(output, src.environment.Environ({}))
96 return BatFileEnviron(output, src.environment.Environ({}))
97 if shell == "cfgForPy":
98 return LauncherFileEnviron(output, environ)
100 return ContextFileEnviron(output, src.environment.Environ({}))
101 raise Exception("FileEnviron: Unknown shell = %s" % shell)
103 class FileEnviron(object):
105 Base class for shell environment
107 def __init__(self, output, environ=None):
111 :param output file: the output file stream.
112 :param environ dict: a potential additional environment.
114 self._do_init(output, environ)
118 easy non exhaustive quick resume for debug print"""
120 "output" : self.output,
121 "environ" : self.environ,
123 return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(res))
126 def _do_init(self, output, environ=None):
130 :param output file: the output file stream.
131 :param environ dict: a potential additional environment.
134 if environ is not None:
135 #if str(type(environ)) == "<type 'instance'>":
136 if id(environ) == id(os.environ):
137 DBG.tofix("set %s environ as python os.environ, are you sure it is safe ?" % self.__class__.__name__, True)
138 self.environ = environ
140 DBG.tofix("set %s environ as COPY of python os.environ, are you sure it is safe ?" % self.__class__.__name__, True)
141 self.environ = dict(os.environ) #make a copy cvw 180320
143 def add_line(self, number):
145 Add some empty lines in the shell file
147 :param number int: the number of lines to add
149 self.output.write("\n" * number)
151 def add_comment(self, comment):
153 Add a comment in the shell file
155 :param comment str: the comment to add
157 self.output.write("# %s\n" % comment)
159 def add_echo(self, text):
161 Add a "echo" in the shell file
163 :param text str: the text to echo
165 self.output.write('echo %s"\n' % text)
167 def add_warning(self, warning):
169 Add a warning "echo" in the shell file
171 :param warning str: the text to echo
173 self.output.write('echo "WARNING %s"\n' % warning)
175 def append_value(self, key, value, sep=os.pathsep):
177 append value to key using sep,
178 if value contains ":" or ";" then raise error
180 :param key str: the environment variable to append
181 :param value str: the value to append to key
182 :param sep str: the separator string
184 # check that value so no contain the system separator
186 if separator in value:
187 raise Exception("FileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
189 if self.environ.is_defined(key):
190 value_list = self.environ.get(key).split(sep)
191 if self.environ._expandvars(value) in value_list:
192 do_append=False # value is already in key path : we don't append it again
193 #print "\nCNC append_value value is already set!! key=%s, val=%s value_list=%s\n" % (key,self.environ._expandvars(value), value_list)
196 self.environ.append_value(key, value,sep)
197 self.set(key, self.get(key) + sep + value)
199 def append(self, key, value, sep=os.pathsep):
201 Same as append_value but the value argument can be a list
203 :param key str: the environment variable to append
204 :param value str or list: the value(s) to append to key
205 :param sep str: the separator string
207 if isinstance(value, list):
209 self.append_value(key, v, sep)
211 self.append_value(key, value, sep)
213 def prepend_value(self, key, value, sep=os.pathsep):
215 prepend value to key using sep,
216 if value contains ":" or ";" then raise error
218 :param key str: the environment variable to prepend
219 :param value str: the value to prepend to key
220 :param sep str: the separator string
222 # check that value so no contain the system separator
224 if separator in value:
225 raise Exception("FileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
228 if self.environ.is_defined(key):
229 value_list = self.environ.get(key).split(sep)
230 exp_val=self.environ._expandvars(value)
231 if exp_val in value_list:
233 #print "\nCNC prepend_value value is already set!! key=%s, val=%s value_list=%s\n" % (key,exp_val, value_list)
234 if not do_not_prepend:
235 self.environ.prepend_value(key, value,sep)
236 self.set(key, value + sep + self.get(key))
238 def prepend(self, key, value, sep=os.pathsep):
240 Same as prepend_value but the value argument can be a list
242 :param key str: the environment variable to prepend
243 :param value str or list: the value(s) to prepend to key
244 :param sep str: the separator string
246 if isinstance(value, list):
247 for v in reversed(value): # prepend list, first item at last to stay first
248 self.prepend_value(key, v, sep)
250 self.prepend_value(key, value, sep)
252 def is_defined(self, key):
254 Check if the key exists in the environment
256 :param key str: the environment variable to check
258 return self.environ.is_defined(key)
260 def set(self, key, value):
262 Set the environment variable 'key' to value 'value'
264 :param key str: the environment variable to set
265 :param value str: the value
267 raise NotImplementedError("set is not implement for this shell!")
271 Get the value of the environment variable "key"
273 :param key str: the environment variable
277 def get_value(self, key):
278 """Get the real value of the environment variable "key"
279 It can help env scripts
280 :param key str: the environment variable
282 return self.environ.get_value(key)
284 def command_value(self, key, command):
286 Get the value given by the system command "command"
287 and put it in the environment variable key.
288 Has to be overwritten in the derived classes
289 This can be seen as a virtual method
291 :param key str: the environment variable
292 :param command str: the command to execute
294 raise NotImplementedError("command_value is not implement "
298 """Add a final instruction in the out file (in case of file generation)
300 :param required bool: Do nothing if required is False
302 raise NotImplementedError("command_value is not implement "
305 class BashFileEnviron(FileEnviron):
307 Class for bash shell.
309 def __init__(self, output, environ=None):
312 :param output file: the output file stream.
313 :param environ dict: a potential additional environment.
315 self._do_init(output, environ)
316 self.output.write(bash_header)
318 def set(self, key, value):
319 """Set the environment variable "key" to value "value"
321 :param key str: the environment variable to set
322 :param value str: the value
324 self.output.write('export %s="%s"\n' % (key, value))
325 self.environ.set(key, value)
328 def command_value(self, key, command):
330 Get the value given by the system command "command"
331 and put it in the environment variable key.
332 Has to be overwritten in the derived classes
333 This can be seen as a virtual method
335 :param key str: the environment variable
336 :param command str: the command to execute
338 self.output.write('export %s=$(%s)\n' % (key, command))
341 class BatFileEnviron(FileEnviron):
343 for Windows batch shell.
345 def __init__(self, output, environ=None):
348 :param output file: the output file stream.
349 :param environ dict: a potential additional environment.
351 self._do_init(output, environ)
352 self.output.write(bat_header)
354 def add_comment(self, comment):
355 """Add a comment in the shell file
357 :param comment str: the comment to add
359 self.output.write("rem %s\n" % comment)
362 """Get the value of the environment variable "key"
364 :param key str: the environment variable
366 return '%%%s%%' % key
368 def set(self, key, value):
369 """Set the environment variable "key" to value "value"
371 :param key str: the environment variable to set
372 :param value str: the value
374 self.output.write('set %s=%s\n' % (key, value))
375 self.environ.set(key, value)
377 def command_value(self, key, command):
379 Get the value given by the system command "command"
380 and put it in the environment variable key.
381 Has to be overwritten in the derived classes
382 This can be seen as a virtual method
384 :param key str: the environment variable
385 :param command str: the command to execute
387 self.output.write('%s > tmp.txt\n' % (command))
388 self.output.write('set /p %s =< tmp.txt\n' % (key))
390 def finish(self, required=True):
392 Add a final instruction in the out file (in case of file generation)
393 In the particular windows case, do nothing
395 :param required bool: Do nothing if required is False
399 class ContextFileEnviron(FileEnviron):
400 """Class for a salome context configuration file.
402 def __init__(self, output, environ=None):
405 :param output file: the output file stream.
406 :param environ dict: a potential additional environment.
408 self._do_init(output, environ)
409 self.output.write(cfg_header)
411 def set(self, key, value):
412 """Set the environment variable "key" to value "value"
414 :param key str: the environment variable to set
415 :param value str: the value
417 self.output.write('%s="%s"\n' % (key, value))
418 self.environ.set(key, value)
421 """Get the value of the environment variable "key"
423 :param key str: the environment variable
425 return '%({0})s'.format(key)
427 def command_value(self, key, command):
429 Get the value given by the system command "command"
430 and put it in the environment variable key.
431 Has to be overwritten in the derived classes
432 This can be seen as a virtual method
434 :param key str: the environment variable
435 :param command str: the command to execute
437 raise NotImplementedError("command_value is not implement "
438 "for salome context files!")
440 def add_echo(self, text):
443 :param text str: the comment to add
445 self.add_comment(text)
447 def add_warning(self, warning):
450 :param text str: the warning to add
452 self.add_comment("WARNING %s" % warning)
454 def prepend_value(self, key, value, sep=os.pathsep):
455 """prepend value to key using sep
457 :param key str: the environment variable to prepend
458 :param value str: the value to prepend to key
459 :param sep str: the separator string
462 if self.environ.is_defined(key):
463 value_list = self.environ.get(key).split(sep)
464 #value cannot be expanded (unlike bash/bat case) - but it doesn't matter.
465 if value in value_list:
466 do_append=False # value is already in key path : we don't append it again
469 self.environ.append_value(key, value,sep)
470 self.output.write('ADD_TO_%s: %s\n' % (key, value))
472 def append_value(self, key, value, sep=os.pathsep):
473 """append value to key using sep
475 :param key str: the environment variable to append
476 :param value str: the value to append to key
477 :param sep str: the separator string
479 self.prepend_value(key, value)
481 def finish(self, required=True):
482 """Add a final instruction in the out file (in case of file generation)
484 :param required bool: Do nothing if required is False
488 def special_path_separator(name):
490 TCLLIBPATH, TKLIBPATH, PV_PLUGIN_PATH environments variables need
491 some exotic path separator.
492 This function gives the separator regarding the name of the variable
493 to append or prepend.
495 :param name str: The name of the variable to find the separator
497 special_blanks_keys=["TCLLIBPATH", "TKLIBPATH"]
498 special_semicolon_keys=["PV_PLUGIN_PATH"]
500 if name in special_blanks_keys: res=" "
501 if name in special_semicolon_keys: res=";"
504 class LauncherFileEnviron:
506 Class to generate a launcher file script
507 (in python syntax) SalomeContext API
509 def __init__(self, output, environ=None):
512 :param output file: the output file stream.
513 :param environ dict: a potential additional environment.
516 if environ is not None:
517 self.environ = environ
519 self.environ = os.environ
520 # Initialize some variables
521 if not "PATH" in self.environ.keys():
522 self.environ["PATH"]=""
523 if not "LD_LIBRARY_PATH" in self.environ.keys():
524 self.environ["LD_LIBRARY_PATH"]=""
525 if not "PYTHONPATH" in self.environ.keys():
526 self.environ["PYTHONPATH"]=""
527 if not "TCLLIBPATH" in self.environ.keys():
528 self.environ["TCLLIBPATH"]=""
529 if not "TKLIBPATH" in self.environ.keys():
530 self.environ["TKLIBPATH"]=""
532 # four whitespaces for first indentation in a python script
534 self.prefix="context."
535 self.setVarEnv="setVariable"
537 self.begin=self.indent+self.prefix
538 self.output.write(Launcher_header)
539 self.specialKeys={"PATH": "Path",
540 "LD_LIBRARY_PATH": "LdLibraryPath",
541 "PYTHONPATH": "PythonPath"}
543 def change_to_launcher(self, value):
547 def add_line(self, number):
548 """Add some empty lines in the launcher file
550 :param number int: the number of lines to add
552 self.output.write("\n" * number)
554 def add_echo(self, text):
557 :param text str: the comment to add
559 self.output.write('# %s"\n' % text)
561 def add_warning(self, warning):
564 :param text str: the warning to add
566 self.output.write('# "WARNING %s"\n' % warning)
568 def append_value(self, key, value, sep=":"):
569 """append value to key using sep,
570 if value contains ":" or ";" then raise error
572 :param key str: the environment variable to append
573 :param value str: the value to append to key
574 :param sep str: the separator string
576 # check that value so no contain the system separator
578 if separator in value:
579 raise Exception("LauncherFileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
581 if self.is_defined(key) :
586 def append(self, key, value, sep=":"):
587 """Same as append_value but the value argument can be a list
589 :param key str: the environment variable to append
590 :param value str or list: the value(s) to append to key
591 :param sep str: the separator string
593 if isinstance(value, list):
595 self.append_value(key, v, sep)
597 self.append_value(key, value, sep)
599 def prepend_value(self, key, value, sep=":"):
600 """prepend value to key using sep,
601 if value contains ":" or ";" then raise error
603 :param key str: the environment variable to prepend
604 :param value str: the value to prepend to key
605 :param sep str: the separator string
607 # check that value so no contain the system separator
609 if separator in value:
610 raise Exception("LauncherFileEnviron append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
612 if self.is_defined(key) :
617 def prepend(self, key, value, sep=":"):
618 """Same as prepend_value but the value argument can be a list
620 :param key str: the environment variable to prepend
621 :param value str or list: the value(s) to prepend to key
622 :param sep str: the separator string
624 if isinstance(value, list):
626 self.prepend_value(key, v, sep)
628 self.prepend_value(key, value, sep)
630 def is_defined(self, key):
631 """Check if the key exists in the environment
633 :param key str: the environment variable to check
635 return key in self.environ.keys()
638 """Get the value of the environment variable "key"
640 :param key str: the environment variable
644 def set(self, key, value):
645 """Set the environment variable "key" to value "value"
647 :param key str: the environment variable to set
648 :param value str: the value
650 self.output.write(self.begin+self.setVarEnv+
651 '(r"%s", r"%s", overwrite=True)\n' %
652 (key, self.change_to_launcher(value)))
653 self.environ[key] = value
655 def get_value(self, key):
656 """Get the real value of the environment variable "key", not ${key}
657 It can help env scripts
658 :param key str: the environment variable
660 return self.environ[key]
662 def add(self, key, value):
663 """prepend value to key using sep
665 :param key str: the environment variable to prepend
666 :param value str: the value to prepend to key
668 if key in self.specialKeys.keys():
669 self.output.write(self.begin+'addTo%s(r"%s")\n' %
670 (self.specialKeys[key],
671 self.change_to_launcher(value)))
672 self.environ[key]+=":"+value
674 sep=special_path_separator(key)
675 self.output.write(self.indent+
676 '#temporary solution!!! have to be defined in API a '
677 '?dangerous? addToSpecial(r"%s", r"%s")\n' %
679 #pathsep not precised because do not know future os launch?
680 self.output.write(self.begin+'addToSpecial(r"%s", r"%s")\n'
681 % (key, self.change_to_launcher(value)))
682 self.environ[key]+=sep+value #here yes we know os for current execution
684 def command_value(self, key, command):
686 Get the value given by the system command "command"
687 and put it in the environment variable key.
689 :param key str: the environment variable
690 :param command str: the command to execute
692 self.output.write(self.indent+'#`%s`\n' % command)
694 import shlex, subprocess
695 args = shlex.split(command)
696 res=subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
697 out, __ = res.communicate()
698 self.output.write(self.begin+
700 '(r"%s", r"%s", overwrite=True)\n' % (key, out))
702 def add_comment(self, comment):
703 # Special comment in case of the distène licence
704 if comment=="DISTENE license":
705 self.output.write(self.indent+
709 '(r"%s", r"%s", overwrite=True)\n' %
710 ('DISTENE_LICENSE_FILE',
711 self.change_to_launcher(
712 'Use global envvar: DLIM8VAR')))
713 self.output.write(self.indent+
717 '(r"%s", r"%s", overwrite=True)\n' %
719 self.change_to_launcher(
722 if "setting environ for" in comment:
723 self.output.write(self.indent+"#[%s]\n" %
724 comment.split("setting environ for ")[1])
727 self.output.write(self.indent+"# %s\n" % comment)
729 def finish(self, required=True):
731 Add a final instruction in the out file (in case of file generation)
732 In the particular launcher case, do nothing
734 :param required bool: Do nothing if required is False
738 class ScreenEnviron(FileEnviron):
739 def __init__(self, output, environ=None):
740 self._do_init(output, environ)
743 def add_line(self, number):
746 def add_comment(self, comment):
749 def add_echo(self, text):
752 def add_warning(self, warning):
755 def write(self, command, name, value, sign="="):
757 self.output.write(" %s%s %s %s %s\n" % \
758 (src.printcolors.printcLabel(command),
759 " " * (12 - len(command)),
760 src.printcolors.printcInfo(name), sign, value))
762 def is_defined(self, name):
763 return name in self.defined
766 return "${%s}" % name
768 def set(self, name, value):
769 self.write("set", name, value)
770 self.defined[name] = value
772 def prepend(self, name, value, sep=":"):
773 if isinstance(value, list):
774 value = sep.join(value)
775 value = value + sep + self.get(name)
776 self.write("prepend", name, value)
778 def append(self, name, value, sep=":"):
779 if isinstance(value, list):
780 value = sep.join(value)
781 value = self.get(name) + sep + value
782 self.write("append", name, value)
784 def command_value(self, key, command):
787 def run_env_script(self, module, script):
788 self.write("load", script, "", sign="")
790 # The SALOME launcher template
792 #! /usr/bin/env python
794 ################################################################
795 # WARNING: this file is automatically generated by SalomeTools #
796 # WARNING: and so could be overwritten at any time. #
797 ################################################################
804 # Add the pwdPath to able to run the launcher after unpacking a package
805 # Used only in case of a salomeTools package
806 out_dir_Path=os.path.dirname(os.path.realpath(__file__))
808 # Preliminary work to initialize path to SALOME Python modules
811 sys.path[:0] = [ 'BIN_KERNEL_INSTALL_DIR' ]
812 os.environ['ABSOLUTE_APPLI_PATH'] = 'KERNEL_INSTALL_DIR'
814 # define folder to store omniorb config (initially in virtual application folder)
816 from salomeContextUtils import setOmniOrbUserPath
818 except Exception as e:
821 # End of preliminary work
823 # salome doc only works for virtual applications. Therefore we overwrite it with this function
824 def _showDoc(modules):
825 for module in modules:
826 modulePath = os.getenv(module+"_ROOT_DIR")
827 if modulePath != None:
828 baseDir = os.path.join(modulePath, "share", "doc", "salome")
829 docfile = os.path.join(baseDir, "gui", module.upper(), "index.html")
830 if not os.path.isfile(docfile):
831 docfile = os.path.join(baseDir, "tui", module.upper(), "index.html")
832 if not os.path.isfile(docfile):
833 docfile = os.path.join(baseDir, "dev", module.upper(), "index.html")
834 if os.path.isfile(docfile):
835 out, err = subprocess.Popen(["xdg-open", docfile]).communicate()
837 print "Online documentation is not accessible for module:", module
839 print module+"_ROOT_DIR not found!"
842 # Identify application path then locate configuration files
845 if args == ['--help']:
846 from salomeContext import usage
850 #from salomeContextUtils import getConfigFileNames
851 #configFileNames, args, unexisting = getConfigFileNames( args, checkExistence=True )
852 #if len(unexisting) > 0:
853 # print "ERROR: unexisting configuration file(s): " + ', '.join(unexisting)
856 # Create a SalomeContext which parses configFileNames to initialize environment
858 from salomeContext import SalomeContext, SalomeContextException
859 SalomeContext.addToSpecial=addToSpecial
860 context = SalomeContext(None)
862 # Here set specific variables, if needed
863 # context.addToPath('mypath')
864 # context.addToLdLibraryPath('myldlibrarypath')
865 # context.addToPythonPath('mypythonpath')
866 # context.setVariable('myvarname', 'value')
869 context.getLogger().setLevel(40)
871 # here your local standalone environment
873 if len(args) >1 and args[0]=='doc':
877 # Start SALOME, parsing command line arguments
878 out, err, status = context.runSalome(args)
881 except SalomeContextException, e:
883 logging.getLogger("salome").error(e)
886 def addToSpecial(self, name, value, pathSep=None):
887 # add special dangerous cases: TCLLIBPATH PV_PLUGIN_PATH etc...
888 # http://computer-programming-forum.com/57-tcl/1dfddc136afccb94.htm
889 # TCLLIBPATH: Tcl treats the contents of that variable as a list. Be happy, for you can now use drive letters on windows.
893 specialBlanksKeys=["TCLLIBPATH", "TKLIBPATH"]
894 specialSemicolonKeys=["PV_PLUGIN_PATH"]
896 if name in specialBlanksKeys: res=" "
897 if name in specialSemicolonKeys: res=";"
903 value = os.path.expandvars(value) # expand environment variables
904 self.getLogger().debug("Add to %s: %s", name, value)
905 env = os.getenv(name, None)
907 os.environ[name] = value
909 os.environ[name] = value + sep + env #explicitely or not special path separator ?whitespace, semicolon?
911 if __name__ == "__main__":
918 #! /usr/bin/env python3
920 ################################################################
921 # WARNING: this file is automatically generated by SalomeTools #
922 # WARNING: and so could be overwritten at any time. #
923 ################################################################
930 # Add the pwdPath to able to run the launcher after unpacking a package
931 # Used only in case of a salomeTools package
932 out_dir_Path=os.path.dirname(os.path.realpath(__file__))
934 # Preliminary work to initialize path to SALOME Python modules
937 sys.path[:0] = [ 'BIN_KERNEL_INSTALL_DIR' ]
938 os.environ['ABSOLUTE_APPLI_PATH'] = 'KERNEL_INSTALL_DIR'
940 # define folder to store omniorb config (initially in virtual application folder)
942 from salomeContextUtils import setOmniOrbUserPath
944 except Exception as e:
947 # End of preliminary work
949 # salome doc only works for virtual applications. Therefore we overwrite it with this function
950 def _showDoc(modules):
951 for module in modules:
952 modulePath = os.getenv(module+"_ROOT_DIR")
953 if modulePath != None:
954 baseDir = os.path.join(modulePath, "share", "doc", "salome")
955 docfile = os.path.join(baseDir, "gui", module.upper(), "index.html")
956 if not os.path.isfile(docfile):
957 docfile = os.path.join(baseDir, "tui", module.upper(), "index.html")
958 if not os.path.isfile(docfile):
959 docfile = os.path.join(baseDir, "dev", module.upper(), "index.html")
960 if os.path.isfile(docfile):
961 out, err = subprocess.Popen(["xdg-open", docfile]).communicate()
963 print("Online documentation is not accessible for module:", module)
965 print(module+"_ROOT_DIR not found!")
968 # Identify application path then locate configuration files
971 if args == ['--help']:
972 from salomeContext import usage
976 #from salomeContextUtils import getConfigFileNames
977 #configFileNames, args, unexisting = getConfigFileNames( args, checkExistence=True )
978 #if len(unexisting) > 0:
979 # print("ERROR: unexisting configuration file(s): " + ', '.join(unexisting))
982 # Create a SalomeContext which parses configFileNames to initialize environment
984 from salomeContext import SalomeContext, SalomeContextException
985 SalomeContext.addToSpecial=addToSpecial
986 context = SalomeContext(None)
988 # Here set specific variables, if needed
989 # context.addToPath('mypath')
990 # context.addToLdLibraryPath('myldlibrarypath')
991 # context.addToPythonPath('mypythonpath')
992 # context.setVariable('myvarname', 'value')
995 context.getLogger().setLevel(40)
997 # here your local standalone environment
999 if len(args) >1 and args[0]=='doc':
1003 # Start SALOME, parsing command line arguments
1004 out, err, status = context.runSalome(args)
1007 except SalomeContextException as e:
1009 logging.getLogger("salome").error(e)
1012 def addToSpecial(self, name, value, pathSep=None):
1013 # add special dangerous cases: TCLLIBPATH PV_PLUGIN_PATH etc...
1014 # http://computer-programming-forum.com/57-tcl/1dfddc136afccb94.htm
1015 # TCLLIBPATH: Tcl treats the contents of that variable as a list. Be happy, for you can now use drive letters on windows.
1019 specialBlanksKeys=["TCLLIBPATH", "TKLIBPATH"]
1020 specialSemicolonKeys=["PV_PLUGIN_PATH"]
1022 if name in specialBlanksKeys: res=" "
1023 if name in specialSemicolonKeys: res=";"
1029 value = os.path.expandvars(value) # expand environment variables
1030 self.getLogger().debug("Add to %s: %s", name, value)
1031 env = os.getenv(name, None)
1033 os.environ[name] = value
1035 os.environ[name] = value + sep + env #explicitely or not special path separator ?whitespace, semicolon?
1037 if __name__ == "__main__":