+ def write_tcl_files(self,
+ forBuild,
+ shell,
+ for_package = None,
+ no_path_init=False,
+ additional_env = {}):
+ """\
+ Create tcl environment files for environment module.
+
+ :param forBuild bool: if true, the build environment
+ :param shell str: the type of file wanted (.sh, .bat)
+ :param for_package bool: if true do specific stuff for required for packages
+ :param no_path_init bool: if true generate a environ file that do not reinitialise paths
+ :param additional_env dict: contains sat_ prefixed variables to help the génération,
+ and also variables to add in the environment.
+ :return: The path to the generated file
+ :rtype: str
+ """
+
+ # get the products informations
+ all_products=self.config.APPLICATION.products
+ products_infos = src.product.get_products_infos(all_products, self.config)
+
+ # set a global environment (we need it to resolve variable references
+ # between dependent products
+ global_environ = src.environment.SalomeEnviron(self.config,
+ src.environment.Environ(additional_env),
+ False)
+ global_environ.set_products(self.logger)
+
+ # The loop on the products
+ for product in all_products:
+ # create one file per product
+ pi = src.product.get_product_config(self.config, product)
+ if "base" not in pi: # we write tcl files only for products in base
+ continue
+
+ # get the global environment, and complete it with sat_ prefixed
+ # prefixed variables which are used to transfer info to
+ # TclFileEnviron class
+ product_env = copy.deepcopy(global_environ.environ)
+ product_env.environ["sat_product_name"] = pi.name
+ product_env.environ["sat_product_version"] = pi.version
+ product_env.environ["sat_product_base_path"] = src.get_base_path(self.config)
+ product_env.environ["sat_product_base_name"] = pi.base
+
+ # store infos in sat_product_load_depend to set dependencies in tcl file
+ sat_product_load_depend=""
+ for p_name,p_info in products_infos:
+ if p_name in pi.depend:
+ sat_product_load_depend+="module load %s/%s/%s;" % (pi.base,
+ p_info.name,
+ p_info.version)
+ if len(sat_product_load_depend)>0:
+ # if there are dependencies, store the module to load (get rid of trailing ;)
+ product_env.environ["sat_product_load_depend"]=sat_product_load_depend[0:-1]
+
+
+ env_file_name = os.path.join(product_env.environ["sat_product_base_path"],
+ "modulefiles",
+ product_env.environ["sat_product_base_name"],
+ product_env.environ["sat_product_name"],
+ product_env.environ["sat_product_version"])
+ prod_dir_name=os.path.dirname(env_file_name)
+ if not os.path.isdir(prod_dir_name):
+ os.makedirs(prod_dir_name)
+
+ env_file = open(env_file_name, "w")
+ file_environ = src.fileEnviron.get_file_environ(env_file,
+ "tcl", product_env)
+ env = SalomeEnviron(self.config,
+ file_environ,
+ False,
+ for_package=for_package)
+ if "Python" in pi.depend:
+ # short cut, env.python_lib is required by set_a_product for salome modules
+ env.has_python="True"
+ env.python_lib=global_environ.get("PYTHON_LIBDIR")
+ env.set_a_product(product, self.logger)
+ env_file.close()
+ if not self.silent:
+ self.logger.write(_(" Create tcl module environment file %s\n") %
+ src.printcolors.printcLabel(env_file_name), 3)
+
+