From 57e376f9c90f44b0aef1dfc8f98f4297b454a733 Mon Sep 17 00:00:00 2001 From: crouzet Date: Wed, 16 Jan 2019 16:03:44 +0100 Subject: [PATCH] =?utf8?q?Implementation=20de=20sat=20#9575=20=20-=20Gesti?= =?utf8?q?on=20dans=20les=20pyconf=20projet=20d'un=20path=20LICENCEPATH=20?= =?utf8?q?=20-=20Ajout=20aux=20produits=20distene=20des=20propri=C3=A9t?= =?utf8?q?=C3=A9s=20is=5Fdistene=20et=20has=5Flicence=20qui=20renseigne=20?= =?utf8?q?vers=20le=20nom=20du=20fichier=20de=20licence=20=C3=A0=20cherche?= =?utf8?q?=20dans=20le=20LICENCEPATH=20=20-=20Pour=20les=20paquets=20:=20u?= =?utf8?q?tilisation=20du=20path=20LICENCEPATH=20pour=20r=C3=A9cup=C3=A9re?= =?utf8?q?r=20le=20fichier=20=20-=20Pour=20les=20autres=20cas=20(sat=20env?= =?utf8?q?iron,=20sat=20laucher,=20sat=20application)=20:=20extraction=20d?= =?utf8?q?e=20la=20cl=C3=A9=20dans=20ce=20fichier=20=20-=20nouvelle=20fonc?= =?utf8?q?tion=20:=20src/product/product=5Fhas=5Flicence()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- commands/config.py | 4 +++- commands/package.py | 31 ++++++++++++++++++++++++------- src/environment.py | 6 ++++++ src/fileEnviron.py | 14 ++++++++++++++ src/product.py | 28 ++++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 8 deletions(-) diff --git a/commands/config.py b/commands/config.py index 31a522c..c83aecf 100644 --- a/commands/config.py +++ b/commands/config.py @@ -359,6 +359,7 @@ class ConfigManager: cfg.PATHS.JOBPATH.append(cfg.VARS.personal_jobs_dir, "") cfg.PATHS["MACHINEPATH"] = src.pyconf.Sequence(cfg.PATHS) cfg.PATHS.MACHINEPATH.append(cfg.VARS.personal_machines_dir, "") + cfg.PATHS["LICENCEPATH"] = src.pyconf.Sequence(cfg.PATHS) # initialise the path with local directory cfg.PATHS["ARCHIVEPATH"].append(cfg.LOCAL.archive_dir, "") @@ -371,7 +372,8 @@ class ConfigManager: "ARCHIVEPATH", #comment this for default archive #8646 "ARCHIVEFTP", "JOBPATH", - "MACHINEPATH"]: + "MACHINEPATH", + "LICENCEPATH"]: if PATH not in cfg.PROJECTS.projects[project]: continue cfg.PATHS[PATH].append(cfg.PROJECTS.projects[project][PATH], "") diff --git a/commands/package.py b/commands/package.py index 8c677af..99bd2d1 100644 --- a/commands/package.py +++ b/commands/package.py @@ -202,13 +202,19 @@ def produce_relative_launcher(config, bin_kernel_install_dir = os.path.join(kernel_root_dir,"bin","salome") # check if the application contains an application module + # check also if the application has a distene product, + # in this case get its licence file name l_product_info = src.product.get_products_infos(config.APPLICATION.products.keys(), config) salome_application_name="Not defined" + distene_licence_file_name=False for prod_name, prod_info in l_product_info: - # look for a salome application + # look for a "salome application" and a distene product + if src.get_property_in_product_cfg(prod_info, "is_distene") == "yes": + distene_licence_file_name = src.product.product_has_licence(prod_info, + config.PATHS.LICENCEPATH) if src.get_property_in_product_cfg(prod_info, "is_salome_application") == "yes": salome_application_name=prod_info.name - continue + # if the application contains an application module, we set ABSOLUTE_APPLI_PATH to it # if not we set it to KERNEL_INSTALL_DIR, which is sufficient, except for salome test if salome_application_name == "Not defined": @@ -253,7 +259,9 @@ def produce_relative_launcher(config, # A hack to put a call to a file for distene licence. # It does nothing to an application that has no distene product - hack_for_distene_licence(filepath) + if distene_licence_file_name: + logger.write("Application has a distene licence file! We use it in package launcher", 5) + hack_for_distene_licence(filepath, distene_licence_file_name) # change the rights in order to make the file executable for everybody os.chmod(filepath, @@ -267,7 +275,7 @@ def produce_relative_launcher(config, return filepath -def hack_for_distene_licence(filepath): +def hack_for_distene_licence(filepath, licence_file): '''Replace the distene licence env variable by a call to a file. :param filepath Str: The path to the launcher to modify. @@ -295,10 +303,10 @@ def hack_for_distene_licence(filepath): del text[num_line +1] text_to_insert =""" import imp try: - distene = imp.load_source('distene_licence', '/data/tmpsalome/salome/prerequis/install/LICENSE/dlim8.var.py') + distene = imp.load_source('distene_licence', '%s') distene.set_distene_variables(context) except: - pass\n""" + pass\n""" % licence_file text.insert(num_line + 1, text_to_insert) for line in text: fout.write(line) @@ -922,13 +930,22 @@ def create_project_for_src_package(config, tmp_working_dir, with_vcs, with_ftp): project_pyconf_file = os.path.join(project_tmp_dir, project_pyconf_name) ff = open(project_pyconf_file, "w") ff.write(PROJECT_TEMPLATE) - if with_ftp: + if with_ftp and len(config.PATHS.ARCHIVEFTP) > 0: ftp_path='ARCHIVEFTP : "'+config.PATHS.ARCHIVEFTP[0] for ftpserver in config.PATHS.ARCHIVEFTP[1:]: ftp_path=ftp_path+":"+ftpserver ftp_path+='"' ff.write("# ftp servers where to search for prerequisite archives\n") ff.write(ftp_path) + # add licence paths if any + if len(config.PATHS.LICENCEPATH) > 0: + licence_path='LICENCEPATH : "'+config.PATHS.LICENCEPATH[0] + for path in config.PATHS.LICENCEPATH[1:]: + licence_path=licence_path+":"+path + licence_path+='"' + ff.write("\n# Where to search for licences\n") + ff.write(licence_path) + ff.close() diff --git a/src/environment.py b/src/environment.py index 88a5959..df6db67 100644 --- a/src/environment.py +++ b/src/environment.py @@ -590,6 +590,12 @@ class SalomeEnviron: self.set_salome_minimal_product_env(pi, logger) self.set_salome_generic_product_env(pi) + # use variable LICENCE_FILE to communicate the licence file name to the environment script + licence_file_name = src.product.product_has_licence(pi, self.cfg.PATHS.LICENCEPATH) + if licence_file_name: + logger.write("licence file found for product %s : %s\n" % (pi.name, licence_file_name), 5) + self.set("LICENCE_FILE", licence_file_name) + if src.product.product_is_cpp(pi): # set a specific environment for cpp modules self.set_salome_minimal_product_env(pi, logger) diff --git a/src/fileEnviron.py b/src/fileEnviron.py index 5f6aeca..0e40367 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -261,6 +261,13 @@ class FileEnviron(object): """ return '${%s}' % key + def get_value(self, key): + """Get the real value of the environment variable "key" + It can help env scripts + :param key str: the environment variable + """ + return self.environ[key] + def command_value(self, key, command): """\ Get the value given by the system command "command" @@ -628,6 +635,13 @@ class LauncherFileEnviron: (key, self.change_to_launcher(value))) self.environ[key] = value + def get_value(self, key): + """Get the real value of the environment variable "key" + It can help env scripts + :param key str: the environment variable + """ + return self.environ[key] + def add(self, key, value): """prepend value to key using sep diff --git a/src/product.py b/src/product.py index 3fd1a2f..5ecd58b 100644 --- a/src/product.py +++ b/src/product.py @@ -930,6 +930,34 @@ def product_has_logo(product_info): else: return False +def product_has_licence(product_info, path): + """Find out if a product has a licence + + :param product_info Config: The configuration specific to the product + :param path Str: The path where to search for the licence + :return: The name of the licence file (the complete path if it is found in the path, else the name, else False + :rtype: Str + """ + if ("properties" in product_info and + "licence" in product_info.properties): + licence_name = product_info.properties.licence + if len(path) > 0: + # search for licence_name in path + # a- consolidate the path into one signe string licence_path + licence_path=path[0] + for lpath in path[1:]: + licence_path=licence_path+":"+lpath + licence_path_list=licence_path.split(":") + licence_fullname = src.find_file_in_lpath(licence_name, licence_path_list) + if licence_fullname: + return licence_fullname + + # if the search of licence in path failed, we return its name (not the full path) + return licence_name + + else: + return False # product has no licence + def product_has_salome_gui(product_info): """Know if a product has a SALOME gui -- 2.30.2