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
26 import src.debug as DBG
32 Class to manage the environment context
34 def __init__(self, environ=None):
35 """Initialization. If the environ argument is passed, the environment
36 will be add to it, else it is the external environment.
40 if environ is not None:
41 self.environ = environ
43 self.environ = os.environ
46 """easy non exhaustive quick resume for debug print"""
47 return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(self.environ))
49 def _expandvars(self, value):
51 replace some $VARIABLE into its actual value in the environment
53 :param value str: the string to be replaced
54 :return: the replaced variable
58 # The string.Template class is a string class
59 # for supporting $-substitutions
60 zt = string.Template(value)
62 value = zt.substitute(self.environ)
63 except KeyError as exc:
65 #raise src.SatException(_("Missing definition "
66 # "in environment: %s") % str(exc))
69 def append_value(self, key, value, sep=os.pathsep):
71 append value to key using sep,
72 if value contains ":" or ";" then raise error
74 :param key str: the environment variable to append
75 :param value str: the value to append to key
76 :param sep str: the separator string
78 # check that value so no contain the system separator
80 if separator in value:
81 raise Exception("Environ append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
83 # check if the key is already in the environment
84 if key in self.environ:
85 value_list = self.environ[key].split(sep)
86 # Check if the value is already in the key value or not
87 if not value in value_list:
88 value_list.append(value)
90 value_list.append(value_list.pop(value_list.index(value)))
91 self.set(key, sep.join(value_list))
95 def append(self, key, value, sep=os.pathsep):
97 Same as append_value but the value argument can be a list
99 :param key str: the environment variable to append
100 :param value str or list: the value(s) to append to key
101 :param sep str: the separator string
103 if isinstance(value, list):
105 self.append_value(key, v, sep)
107 self.append_value(key, value, sep)
109 def prepend_value(self, key, value, sep=os.pathsep):
111 prepend value to key using sep,
112 if value contains ":" or ";" then raise error
114 :param key str: the environment variable to prepend
115 :param value str: the value to prepend to key
116 :param sep str: the separator string
118 # check that value so no contain the system separator
120 if separator in value:
121 raise Exception("Environ append key '%s' value '%s' contains forbidden character '%s'" % (key, value, separator))
123 # check if the key is already in the environment
124 if key in self.environ:
125 value_list = self.environ[key].split(sep)
126 if not value in value_list:
127 value_list.insert(0, value)
129 value_list.insert(0, value_list.pop(value_list.index(value)))
130 self.set(key, sep.join(value_list))
134 def prepend(self, key, value, sep=os.pathsep):
136 Same as prepend_value but the value argument can be a list
138 :param key str: the environment variable to prepend
139 :param value str or list: the value(s) to prepend to key
140 :param sep str: the separator string
142 if isinstance(value, list):
143 for v in reversed(value): # prepend list, first item at last to stay first
144 self.prepend_value(key, v, sep)
146 self.prepend_value(key, value, sep)
148 def is_defined(self, key):
150 Check if the key exists in the environment
152 :param key str: the environment variable to check
154 return key in self.environ.keys()
156 def set(self, key, value):
158 Set the environment variable "key" to value "value"
160 :param key str: the environment variable to set
161 :param value str: the value
163 self.environ[key] = self._expandvars(value)
167 Get the value of the environment variable "key"
169 :param key str: the environment variable
171 if key in self.environ:
172 return self.environ[key]
176 def get_value(self, key):
178 Get the value of the environment variable "key"
179 This method is added for API compatibility with FileEnviron class
181 :param key str: the environment variable
189 Class to manage the environment of SALOME.
196 enable_simple_env_script = True):
200 :param cfg Config: the global config
201 :param environ Environ: the Environ instance where
202 to store the environment variables
203 :param forBuild bool: If true, it is a launch environment,
205 :param for_package str: If not None, produce a relative environment
206 designed for a package.
208 self.environ = environ
210 self.forBuild = forBuild
211 self.for_package = for_package
212 self.enable_simple_env_script = enable_simple_env_script
214 self.has_python = False
217 """easy almost exhaustive quick resume for debug print"""
219 "environ" : self.environ,
220 "forBuild" : self.forBuild,
221 "for_package" : self.for_package,
223 return "%s(\n%s\n)" % (self.__class__.__name__, PP.pformat(res))
225 def append(self, key, value, sep=os.pathsep):
227 append value to key using sep
229 :param key str: the environment variable to append
230 :param value str: the value to append to key
231 :param sep str: the separator string
233 return self.environ.append(key, value, sep)
235 def prepend(self, key, value, sep=os.pathsep):
237 prepend value to key using sep
239 :param key str: the environment variable to prepend
240 :param value str: the value to prepend to key
241 :param sep str: the separator string
243 return self.environ.prepend(key, value, sep)
245 def is_defined(self, key):
247 Check if the key exists in the environment
249 :param key str: the environment variable to check
251 return self.environ.is_defined(key)
255 Get the value of the environment variable "key"
257 :param key str: the environment variable
259 return self.environ.get(key)
261 def get_value(self, key):
263 Get the real value of the environment variable "key"
264 This method is added for API compatibility with FileEnviron class
266 :param key str: the environment variable
268 if key in self.environ:
269 return self.environ[key]
273 def set(self, key, value):
275 Set the environment variable "key" to value "value"
277 :param key str: the environment variable to set
278 :param value str: the value
280 # check if value needs to be evaluated
281 if value is not None and value.startswith("`") and value.endswith("`"):
282 res = subprocess.Popen("echo %s" % value,
284 stdout=subprocess.PIPE).communicate()
285 value = res[0].strip()
287 return self.environ.set(key, value)
291 Write the environment to out
293 :param out file: the stream where to write the environment
295 for k in self.environ.environ.keys():
300 out.write("%s=%s\n" % (k, value))
302 def add_line(self, nb_line):
304 Add empty lines to the out stream (in case of file generation)
306 :param nb_line int: the number of empty lines to add
308 if 'add_line' in dir(self.environ):
309 self.environ.add_line(nb_line)
311 def add_comment(self, comment):
313 Add a commentary to the out stream (in case of file generation)
315 :param comment str: the commentary to add
317 if 'add_comment' in dir(self.environ):
318 self.environ.add_comment(comment)
320 def add_warning(self, warning):
322 Add a warning to the out stream (in case of file generation)
324 :param warning str: the warning to add
326 if 'add_warning' in dir(self.environ):
327 self.environ.add_warning(warning)
331 Add a final instruction in the out file (in case of file generation)
333 :param required bool: Do nothing if required is False
335 if 'finish' in dir(self.environ):
336 self.environ.add_line(1)
338 # self.environ.add_comment("clean all the path")
339 self.environ.finish()
341 def set_python_libdirs(self):
342 """Set some generic variables for python library paths"""
343 ver = self.get('PYTHON_VERSION')
344 self.set('PYTHON_LIBDIR', os.path.join('lib',
347 self.python_lib = self.get('PYTHON_LIBDIR')
348 self.has_python = True
350 def set_application_env(self, logger):
352 Sets the environment defined in the APPLICATION file.
354 :param logger Logger: The logger instance to display messages
358 self.set("PRODUCT_ROOT_DIR", "out_dir_Path")
360 self.cfg.APPLICATION.environ.PRODUCT_ROOT_DIR = src.pyconf.Reference(self.cfg, src.pyconf.DOLLAR, "workdir")
362 # these sensitive variables are reset to avoid bad environment interactions
364 self.add_comment("reset these sensitive variables to avoid bad environment interactions")
365 self.add_comment("comment these to lines if you wish a different behaviour")
366 self.set("LD_LIBRARY_PATH", "")
367 self.set("PYTHONPATH", "")
370 # Set the variables defined in the "environ" section
371 if 'environ' in self.cfg.APPLICATION:
372 # we write PRODUCT environment it in order to conform to
374 self.add_comment("PRODUCT environment")
375 self.load_cfg_environment(self.cfg.APPLICATION.environ)
376 if self.forBuild and "build" in self.cfg.APPLICATION.environ:
377 self.load_cfg_environment(self.cfg.APPLICATION.environ.build)
378 if not self.forBuild and "launch" in self.cfg.APPLICATION.environ:
379 self.load_cfg_environment(self.cfg.APPLICATION.environ.launch)
383 def set_salome_minimal_product_env(self, product_info, logger):
385 Sets the minimal environment for a SALOME product.
386 xxx_ROOT_DIR and xxx_SRC_DIR
388 :param product_info Config: The product description
389 :param logger Logger: The logger instance to display messages
392 DBG.write("set_salome_minimal_product_env", product_info)
393 root_dir = product_info.name + "_ROOT_DIR"
394 if 'install_dir' in product_info and product_info.install_dir:
395 self.set(root_dir, product_info.install_dir)
396 elif not self.silent:
397 logger.write(" " + _("No install_dir for product %s\n") %
398 product_info.name, 5)
400 source_in_package = src.get_property_in_product_cfg(product_info,
401 "sources_in_package")
402 if not self.for_package or source_in_package == "yes":
403 # set source dir, unless no source dir
404 if not src.product.product_is_fixed(product_info):
405 src_dir = product_info.name + "_SRC_DIR"
406 if not self.for_package:
407 self.set(src_dir, product_info.source_dir)
409 self.set(src_dir, os.path.join("out_dir_Path",
411 os.path.basename(product_info.source_dir)))
413 def expand_salome_modules(self, pi):
414 if 'component_name' in pi:
415 compo_name = pi.component_name
418 self.prepend('SALOME_MODULES', compo_name, ',')
421 def set_salome_generic_product_env(self, pi):
423 Sets the generic environment for a SALOME product.
425 :param pi Config: The product description
427 # Construct XXX_ROOT_DIR
428 env_root_dir = self.get(pi.name + "_ROOT_DIR")
429 l_binpath_libpath = []
431 # create additional ROOT_DIR for CPP components
432 if 'component_name' in pi:
433 compo_name = pi.component_name
434 if compo_name + "CPP" == pi.name:
435 compo_root_dir = compo_name + "_ROOT_DIR"
436 envcompo_root_dir = os.path.join(
437 self.cfg.TOOLS.common.install_root, compo_name )
438 self.set(compo_root_dir , envcompo_root_dir)
439 bin_path = os.path.join(envcompo_root_dir, 'bin', 'salome')
440 lib_path = os.path.join(envcompo_root_dir, 'lib', 'salome')
441 l_binpath_libpath.append( (bin_path, lib_path) )
444 if src.get_property_in_product_cfg(pi, "fhs"):
445 lib_path = os.path.join(env_root_dir, 'lib')
446 bin_path = os.path.join(env_root_dir, 'bin')
448 # if the application doesn't include python, we don't need these two lines
449 pylib_path = os.path.join(env_root_dir, self.python_lib)
451 lib_path = os.path.join(env_root_dir, 'lib', 'salome')
452 bin_path = os.path.join(env_root_dir, 'bin', 'salome')
454 # if the application doesn't include python, we don't need these two lines
455 pylib_path = os.path.join(env_root_dir, self.python_lib, 'salome')
457 # Construct the paths to prepend to PATH and LD_LIBRARY_PATH and
459 l_binpath_libpath.append( (bin_path, lib_path) )
461 for bin_path, lib_path in l_binpath_libpath:
462 if not self.forBuild:
463 self.prepend('PATH', bin_path)
464 if src.architecture.is_windows():
465 self.prepend('PATH', lib_path)
467 self.prepend('LD_LIBRARY_PATH', lib_path)
469 l = [ bin_path, lib_path ]
470 if not src.product.product_is_wheel(pi):
473 self.prepend('PYTHONPATH', l)
475 def set_cpp_env(self, product_info):
477 Sets the generic environment for a SALOME cpp product.
479 :param product_info Config: The product description
481 # Construct XXX_ROOT_DIR
482 env_root_dir = self.get(product_info.name + "_ROOT_DIR")
483 l_binpath_libpath = []
485 # Construct the paths to prepend to PATH and LD_LIBRARY_PATH and
487 bin_path = os.path.join(env_root_dir, 'bin')
488 lib_path = os.path.join(env_root_dir, 'lib')
489 l_binpath_libpath.append( (bin_path, lib_path) )
491 for bin_path, lib_path in l_binpath_libpath:
492 if not self.forBuild:
493 self.prepend('PATH', bin_path)
494 if src.architecture.is_windows():
495 self.prepend('PATH', lib_path)
497 self.prepend('LD_LIBRARY_PATH', lib_path)
499 l = [ bin_path, lib_path ]
501 l.append(os.path.join(env_root_dir, self.python_lib))
502 self.prepend('PYTHONPATH', l)
504 def load_cfg_environment(self, cfg_env):
506 Loads environment defined in cfg_env
508 :param cfg_env Config: A config containing an environment
510 # Loop on cfg_env values
511 for env_def in cfg_env:
512 val = cfg_env[env_def]
514 # if it is env_script, do not do anything (reserved keyword)
515 if env_def == "env_script":
518 # if it is a dict, do not do anything
519 if isinstance(val, src.pyconf.Mapping):
522 # if it is a list, loop on its values
523 if isinstance(val, src.pyconf.Sequence):
524 # transform into list of strings
530 # "_" means that the value must be prepended
531 if env_def.startswith("_"):
532 # separator exception for PV_PLUGIN_PATH
533 if env_def[1:] == 'PV_PLUGIN_PATH':
534 self.prepend(env_def[1:], val, ';')
536 self.prepend(env_def[1:], val)
537 elif env_def.endswith("_"):
538 # separator exception for PV_PLUGIN_PATH
539 if env_def[:-1] == 'PV_PLUGIN_PATH':
540 self.append(env_def[:-1], val, ';')
542 self.append(env_def[:-1], val)
544 self.set(env_def, val)
546 def set_a_product(self, product, logger):
548 Sets the environment of a product.
550 :param product str: The product name
551 :param logger Logger: The logger instance to display messages
554 # Get the informations corresponding to the product
555 pi = src.product.get_product_config(self.cfg, product)
557 # skip compile time products at run time
558 if not self.forBuild:
559 if src.product.product_is_compile_time(pi):
562 # skip pip products when pip is activated and installation is done in python
563 #if (src.appli_test_property(self.cfg,"pip", "yes") and
564 # src.product.product_test_property(pi,"pip", "yes") and
565 # src.appli_test_property(self.cfg,"pip_install_dir", "python") ):
568 # skip mesa products (if any) at run time,
569 # unless use_mesa property was activated
570 if not self.forBuild:
571 if not ("APPLICATION" in self.cfg and
572 "properties" in self.cfg.APPLICATION and
573 "use_mesa" in self.cfg.APPLICATION.properties and
574 self.cfg.APPLICATION.properties.use_mesa == "yes") :
575 if ("properties" in pi and
576 "is_mesa" in pi.properties and
577 pi.properties.is_mesa == "yes") :
578 logger.write(_("Skip mesa product %s\n") % pi.name, 4)
583 pi.install_dir = os.path.join(
586 os.path.basename(pi.install_dir))
589 logger.write(_("Setting environment for %s\n") % product, 4)
592 self.add_comment('setting environ for ' + product)
594 # Do not define environment if the product is native
595 if src.product.product_is_native(pi):
596 if src.product.product_has_env_script(pi):
597 self.run_env_script(pi, native=True)
600 # Set an additional environment for SALOME products
601 if src.product.product_is_salome(pi):
602 # set environment using definition of the product
603 self.set_salome_minimal_product_env(pi, logger)
604 self.set_salome_generic_product_env(pi)
607 # Expand SALOME_MODULES variable for products which have a salome gui
608 if src.product.product_has_salome_gui(pi):
609 self.expand_salome_modules(pi)
611 # use variable LICENCE_FILE to communicate the licence file name to the environment script
612 licence_file_name = src.product.product_has_licence(pi, self.cfg.PATHS.LICENCEPATH)
613 if licence_file_name:
614 logger.write("licence file found for product %s : %s\n" % (pi.name, licence_file_name), 5)
615 self.set("LICENCE_FILE", licence_file_name)
617 if src.product.product_is_cpp(pi):
618 # set a specific environment for cpp modules
619 self.set_salome_minimal_product_env(pi, logger)
622 if src.product.product_is_generated(pi):
623 if "component_name" in pi:
624 # hack the source and install directories in order to point
625 # on the generated product source install directories
626 install_dir_save = pi.install_dir
627 source_dir_save = pi.source_dir
629 pi.install_dir = os.path.join(self.cfg.APPLICATION.workdir,
630 self.cfg.INTERNAL.config.install_dir,
633 pi.install_dir = os.path.join("out_dir_Path",
636 pi.source_dir = os.path.join(self.cfg.APPLICATION.workdir,
639 pi.name = pi.component_name
640 self.set_salome_minimal_product_env(pi, logger)
641 self.set_salome_generic_product_env(pi)
643 # Put original values
644 pi.install_dir = install_dir_save
645 pi.source_dir = source_dir_save
648 # Put the environment define in the configuration of the product
650 self.load_cfg_environment(pi.environ)
651 if self.forBuild and "build" in pi.environ:
652 self.load_cfg_environment(pi.environ.build)
653 if not self.forBuild and "launch" in pi.environ:
654 self.load_cfg_environment(pi.environ.launch)
655 # if product_info defines a env_scripts, load it
656 if 'env_script' in pi.environ:
657 self.run_env_script(pi, logger)
662 def run_env_script(self, product_info, logger=None, native=False):
664 Runs an environment script.
666 :param product_info Config: The product description
667 :param logger Logger: The logger instance to display messages
668 :param native Boolean: if True load set_native_env instead of set_env
670 env_script = product_info.environ.env_script
671 # Check that the script exists
672 if not os.path.exists(env_script):
673 raise src.SatException(_("Environment script not found: %s") %
676 if not self.silent and logger is not None:
677 logger.write(" ** load %s\n" % env_script, 4)
679 # import the script and run the set_env function
682 pyproduct = imp.load_source(product_info.name + "_env_script",
685 if self.forBuild and "set_env_build" in dir(pyproduct):
686 pyproduct.set_env_build(self,
687 product_info.install_dir,
688 product_info.version)
689 elif (not self.forBuild) and "set_env_launch" in dir(pyproduct):
690 pyproduct.set_env_launch(self,
691 product_info.install_dir,
692 product_info.version)
694 # at least this one is mandatory,
695 # if set_env_build and set_env_build are not defined
696 pyproduct.set_env(self,
697 product_info.install_dir,
698 product_info.version)
700 # not mandatory, if set_nativ_env not defined, we do nothing
701 if "set_nativ_env" in dir(pyproduct):
702 pyproduct.set_nativ_env(self)
704 __, exceptionValue, exceptionTraceback = sys.exc_info()
705 print(exceptionValue)
707 traceback.print_tb(exceptionTraceback)
708 traceback.print_exc()
711 def set_products(self, logger, src_root=None):
713 Sets the environment for all the products.
715 :param logger Logger: The logger instance to display messages
716 :param src_root src: the application working directory
719 self.add_comment('setting environ for all products')
721 # Make sure that the python lib dirs are set after python
722 if "Python" in self.cfg.APPLICATION.products:
723 self.set_a_product("Python", logger)
724 self.set_python_libdirs()
726 # The loop on the products
727 for product in self.cfg.APPLICATION.products.keys():
728 if product == "Python":
730 self.set_a_product(product, logger)
732 def set_full_environ(self, logger, env_info):
734 Sets the full environment for products
735 specified in env_info dictionary.
737 :param logger Logger: The logger instance to display messages
738 :param env_info list: the list of products
740 DBG.write("set_full_environ for", env_info)
741 # DBG.write("set_full_environ config", self.cfg.APPLICATION.environ, True)
743 # set product environ
744 self.set_application_env(logger)
746 if "Python" in env_info:
747 self.set_a_product("Python", logger)
748 self.set_python_libdirs()
751 for product in env_info:
752 if product == "Python":
754 self.set_a_product(product, logger)
758 Class to dump the environment to a file.
760 def __init__(self, config, logger, out_dir, src_root, env_info=None):
764 :param cfg Config: the global config
765 :param logger Logger: The logger instance to display messages
766 :param out_dir str: The directory path where t put the output files
767 :param src_root str: The application working directory
768 :param env_info str: The list of products to add in the files.
772 self.out_dir = out_dir
773 self.src_root= src_root
775 self.env_info = env_info
777 def write_tcl_files(self,
782 additional_env = {}):
784 Create tcl environment files for environment module.
786 :param forBuild bool: if true, the build environment
787 :param shell str: the type of file wanted (.sh, .bat)
788 :param for_package bool: if true do specific stuff for required for packages
789 :param no_path_init bool: if true generate a environ file that do not reinitialise paths
790 :param additional_env dict: contains sat_ prefixed variables to help the génération,
791 and also variables to add in the environment.
792 :return: The path to the generated file
796 # get the products informations
797 all_products=self.config.APPLICATION.products
798 products_infos = src.product.get_products_infos(all_products, self.config)
800 # set a global environment (we need it to resolve variable references
801 # between dependent products
802 global_environ = src.environment.SalomeEnviron(self.config,
803 src.environment.Environ(additional_env),
805 global_environ.set_products(self.logger)
807 # The loop on the products
808 for product in all_products:
809 # create one file per product
810 pi = src.product.get_product_config(self.config, product)
811 if "base" not in pi: # we write tcl files only for products in base
814 # get the global environment, and complete it with sat_ prefixed
815 # prefixed variables which are used to transfer info to
816 # TclFileEnviron class
817 product_env = copy.deepcopy(global_environ.environ)
818 product_env.environ["sat_product_name"] = pi.name
819 product_env.environ["sat_product_version"] = pi.version
820 product_env.environ["sat_product_base_path"] = src.get_base_path(self.config)
821 product_env.environ["sat_product_base_name"] = pi.base
823 # store infos in sat_product_load_depend to set dependencies in tcl file
824 sat_product_load_depend=""
825 for p_name,p_info in products_infos:
826 if p_name in pi.depend:
827 sat_product_load_depend+="module load %s/%s/%s;" % (pi.base,
830 if len(sat_product_load_depend)>0:
831 # if there are dependencies, store the module to load (get rid of trailing ;)
832 product_env.environ["sat_product_load_depend"]=sat_product_load_depend[0:-1]
835 env_file_name = os.path.join(product_env.environ["sat_product_base_path"],
837 product_env.environ["sat_product_base_name"],
838 product_env.environ["sat_product_name"],
839 product_env.environ["sat_product_version"])
840 prod_dir_name=os.path.dirname(env_file_name)
841 if not os.path.isdir(prod_dir_name):
842 os.makedirs(prod_dir_name)
844 env_file = open(env_file_name, "w")
845 file_environ = src.fileEnviron.get_file_environ(env_file,
847 env = SalomeEnviron(self.config,
850 for_package=for_package)
851 if "Python" in pi.depend:
852 # short cut, env.python_lib is required by set_a_product for salome modules
853 env.has_python="True"
854 env.python_lib=global_environ.get("PYTHON_LIBDIR")
855 env.set_a_product(product, self.logger)
858 self.logger.write(_(" Create tcl module environment file %s\n") %
859 src.printcolors.printcLabel(env_file_name), 3)
862 def write_env_file(self,
868 additional_env = {}):
870 Create an environment file.
872 :param filename str: the file path
873 :param forBuild bool: if true, the build environment
874 :param shell str: the type of file wanted (.sh, .bat)
875 :param for_package bool: if true do specific stuff for required for packages
876 :param no_path_init bool: if true generate a environ file that do not reinitialise paths
877 :param additional_env dict: contains sat_ prefixed variables to help the génération,
878 and also variables to add in the environment.
879 :return: The path to the generated file
883 self.logger.write(_("Create environment file %s\n") %
884 src.printcolors.printcLabel(filename), 3)
886 # create then env object
887 env_file = open(os.path.join(self.out_dir, filename), "w")
889 # we duplicate additional_env, and transmit it to fileEnviron, which will use its sat_ prefixed variables.
890 # the other variables of additional_env are added to the environement file at the end of this function.
891 salome_env = copy.deepcopy(additional_env)
892 file_environ = src.fileEnviron.get_file_environ(env_file,
894 src.environment.Environ(salome_env))
896 # specify we don't want to reinitialise paths
897 # path will keep the inherited value, which will be appended with new values.
898 file_environ.set_no_init_path()
900 env = SalomeEnviron(self.config,
903 for_package=for_package)
905 env.silent = self.silent
907 # Set the environment
908 if self.env_info is not None:
909 env.set_full_environ(self.logger, self.env_info)
911 # set env from the APPLICATION
912 env.set_application_env(self.logger)
915 env.set_products(self.logger,
916 src_root=self.src_root)
918 # Add the additional environment if it is not empty
919 if len(additional_env) != 0:
921 env.add_comment("[APPLI variables]")
922 for variable in additional_env:
923 if not variable.startswith("sat_"):
924 # by convention variables starting with sat_ are used to transfer information,
925 # not to be written in env
926 env.set(variable, additional_env[variable])
928 # finalise the writing and close the file
937 Definition of a Shell.
939 def __init__(self, name, extension):
943 :param name str: the shell name
944 :param extension str: the shell extension
947 self.extension = extension
949 def load_environment(config, build, logger):
951 Loads the environment (used to run the tests, for example).
953 :param config Config: the global config
954 :param build bool: build environement if True
955 :param logger Logger: The logger instance to display messages
957 environ = SalomeEnviron(config, Environ(os.environ), build)
958 environ.set_application_env(logger)
959 environ.set_products(logger)