X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fproduct.py;h=81ad048a261fc04f14236e95b431a40b0b7298bc;hb=31892e4d1e769f1c8fb38121529adea099253dfb;hp=b5ae9cb25141bd2dfdfb12519e42636e3687c837;hpb=82899d9600b0e569e7001eedc192bd0e74b2253e;p=tools%2Fsat.git diff --git a/src/product.py b/src/product.py index b5ae9cb..81ad048 100644 --- a/src/product.py +++ b/src/product.py @@ -26,6 +26,7 @@ import src AVAILABLE_VCS = ['git', 'svn', 'cvs'] config_expression = "^config-\d+$" +VERSION_DELIMITER = "_to_" def get_product_config(config, product_name, with_install_dir=True): '''Get the specific configuration of a product from the global configuration @@ -34,7 +35,7 @@ def get_product_config(config, product_name, with_install_dir=True): :param product_name str: The name of the product :param with_install_dir boolean: If false, do not provide an install directory (at false only for internal use - of the function get_install_dir) + of the function check_config_exists) :return: the specific configuration of the product :rtype: Config ''' @@ -51,6 +52,7 @@ def get_product_config(config, product_name, with_install_dir=True): debug = 'no' dev = 'no' base = 'maybe' + section = None if isinstance(version, src.pyconf.Mapping): dic_version = version # Get the version/tag @@ -67,9 +69,13 @@ def get_product_config(config, product_name, with_install_dir=True): if 'dev' in dic_version: dev = dic_version.dev - # Get the dev if any + # Get the base if any if 'base' in dic_version: base = dic_version.base + + # Get the section if any + if 'section' in dic_version: + section = dic_version.section vv = version # substitute some character with _ in order to get the correct definition @@ -79,21 +85,13 @@ def get_product_config(config, product_name, with_install_dir=True): prod_info = None if product_name in config.PRODUCTS: - # If it exists, get the information of the product_version - if "version_" + vv in config.PRODUCTS[product_name]: - # returns specific information for the given version - prod_info = config.PRODUCTS[product_name]["version_" + vv] - prod_info.section = "version_" + vv - # Get the standard informations - elif "default" in config.PRODUCTS[product_name]: - # returns the generic information (given version not found) - prod_info = config.PRODUCTS[product_name].default - prod_info.section = "default" + # Search for the product description in the configuration + prod_info = get_product_section(config, product_name, vv, section) # merge opt_depend in depend if prod_info is not None and 'opt_depend' in prod_info: for depend in prod_info.opt_depend: - if depend in config.PRODUCTS: + if depend in config.APPLICATION.products: prod_info.depend.append(depend,'') # In case of a product get with a vcs, @@ -111,8 +109,9 @@ def get_product_config(config, product_name, with_install_dir=True): # In case of a fixed product, # define the install_dir (equal to the version) - if prod_info is not None and prod_info.get_source=="fixed": + if prod_info is not None and os.path.isdir(version): prod_info.install_dir = version + prod_info.get_source = "fixed" # Check if the product is defined as native in the application if prod_info is not None: @@ -130,12 +129,34 @@ def get_product_config(config, product_name, with_install_dir=True): prod_info = src.pyconf.Config() prod_info.name = product_name prod_info.get_source = "native" - + + # If there is no definition but the product is fixed, + # construct a new definition containing only the product name + if prod_info is None and os.path.isdir(version): + prod_info = src.pyconf.Config() + prod_info.name = product_name + prod_info.get_source = "fixed" + prod_info.addMapping("environ", src.pyconf.Mapping(prod_info), "") + + # If prod_info is still None, it means that there is no product definition # in the config. The user has to provide it. if prod_info is None: - msg = _("No definition found for the product %s\n" - "Please create a %s.pyconf file." % (product_name, product_name)) + prod_pyconf_path = src.find_file_in_lpath(product_name + ".pyconf", + config.PATHS.PRODUCTPATH) + if not prod_pyconf_path: + msg = _("""\ +No definition found for the product %(1)s. +Please create a %(2)s.pyconf file somewhere in: +%(3)s""") % { + "1": product_name, + "2": product_name, + "3": config.PATHS.PRODUCTPATH } + else: + msg = _("""\ +No definition corresponding to the version %(1)s was found in the file: + %(2)s. +Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path} raise src.SatException(msg) # Set the debug, dev and version keys @@ -154,9 +175,8 @@ def get_product_config(config, product_name, with_install_dir=True): arch_path = src.find_file_in_lpath(arch_name, config.PATHS.ARCHIVEPATH) if not arch_path: - msg = _("Archive %(arch_name)s for %(prod_name)s not found:" - "\n" % {"arch_name" : arch_name, - "prod_name" : prod_info.name}) + msg = _("Archive %(1)s for %(2)s not found.\n") % \ + {"1" : arch_name, "2" : prod_info.name} raise src.SatException(msg) prod_info.archive_info.archive_name = arch_path else: @@ -167,9 +187,8 @@ def get_product_config(config, product_name, with_install_dir=True): arch_name, config.PATHS.ARCHIVEPATH) if not arch_path: - msg = _("Archive %(arch_name)s for %(prod_name)s not found:" - "\n" % {"arch_name" : arch_name, - "prod_name" : prod_info.name}) + msg = _("Archive %(1)s for %(2)s not found:\n") % \ + {"1" : arch_name, "2" : prod_info.name} raise src.SatException(msg) prod_info.archive_info.archive_name = arch_path @@ -178,9 +197,9 @@ def get_product_config(config, product_name, with_install_dir=True): if product_has_script(prod_info): # Check the compil_script key existence if "compil_script" not in prod_info: - msg = _("No compilation script found for the product %s\n" - "Please provide a \"compil_script\" key in its definition." - % (product_name)) + msg = _("""\ +No compilation script found for the product %s. +Please provide a 'compil_script' key in its definition.""") % product_name raise src.SatException(msg) # Get the path of the script @@ -192,15 +211,18 @@ def get_product_config(config, product_name, with_install_dir=True): config.PATHS.PRODUCTPATH, "compil_scripts") if not script_path: - raise src.SatException(_("Compilation script not found: %s") % - script_name) + raise src.SatException( + _("Compilation script not found: %s") % script_name) prod_info.compil_script = script_path + if src.architecture.is_windows(): + prod_info.compil_script = prod_info.compil_script[:-len(".sh")] + ".bat" # Check that the script is executable if not os.access(prod_info.compil_script, os.X_OK): - raise src.SatException( - _("Compilation script cannot be executed: %s") % - prod_info.compil_script) + #raise src.SatException( + # _("Compilation script cannot be executed: %s") % + # prod_info.compil_script) + print("WARNING: Compilation script cannot be executed:\n %s" % prod_info.compil_script) # Get the full paths of all the patches if product_has_patches(prod_info): @@ -244,11 +266,75 @@ def get_product_config(config, product_name, with_install_dir=True): # The variable with_install_dir is at false only for internal use # of the function get_install_dir + # Save the install_dir key if there is any + if "install_dir" in prod_info and not "install_dir_save" in prod_info: + prod_info.install_dir_save = prod_info.install_dir + + # if it is not the first time the install_dir is computed, it means + # that install_dir_save exists and it has to be taken into account. + if "install_dir_save" in prod_info: + prod_info.install_dir = prod_info.install_dir_save + # Set the install_dir key prod_info.install_dir = get_install_dir(config, base, version, prod_info) return prod_info +def get_product_section(config, product_name, version, section=None): + '''Get the product description from the configuration + + :param config Config: The global configuration + :param product_name str: The product name + :param version str: The version of the product + :param section str: The searched section (if not None, the section is + explicitly given + :return: The product description + :rtype: Config + ''' + + # if section is not None, try to get the corresponding section + if section: + if section not in config.PRODUCTS[product_name]: + return None + # returns specific information for the given version + prod_info = config.PRODUCTS[product_name][section] + prod_info.section = section + prod_info.from_file = config.PRODUCTS[product_name].from_file + return prod_info + + # If it exists, get the information of the product_version + if "version_" + version in config.PRODUCTS[product_name]: + # returns specific information for the given version + prod_info = config.PRODUCTS[product_name]["version_" + version] + prod_info.section = "version_" + version + prod_info.from_file = config.PRODUCTS[product_name].from_file + return prod_info + + # Else, check if there is a description for multiple versions + l_section_name = config.PRODUCTS[product_name].keys() + l_section_ranges = [section_name for section_name in l_section_name + if VERSION_DELIMITER in section_name] + for section_range in l_section_ranges: + minimum, maximum = section_range.split(VERSION_DELIMITER) + if (src.only_numbers(version) >= src.only_numbers(minimum) + and src.only_numbers(version) <= src.only_numbers(maximum)): + # returns specific information for the versions + prod_info = config.PRODUCTS[product_name][section_range] + prod_info.section = section_range + prod_info.from_file = config.PRODUCTS[product_name].from_file + return prod_info + + # Else, get the standard informations + if "default" in config.PRODUCTS[product_name]: + # returns the generic information (given version not found) + prod_info = config.PRODUCTS[product_name].default + prod_info.section = "default" + prod_info.from_file = config.PRODUCTS[product_name].from_file + return prod_info + + # if noting was found, return None + return None + def get_install_dir(config, base, version, prod_info): '''Compute the installation directory of a given product @@ -348,7 +434,10 @@ def check_config_exists(config, prod_dir, prod_info): # If there is no dependency, it is the right path if len(prod_info.depend)==0: - return True, os.path.join(prod_dir, dir_or_file) + compile_cfg = src.pyconf.Config(config_file) + if len(compile_cfg) == 0: + return True, os.path.join(prod_dir, dir_or_file) + continue # check if there is the config described in the file corresponds the # dependencies of the product @@ -367,6 +456,12 @@ def check_config_exists(config, prod_dir, prod_info): if prod_dep_info.version != compile_cfg[prod_dep]: config_corresponds = False break + + for prod_name in compile_cfg: + if prod_name not in prod_info.depend: + config_corresponds = False + break + if config_corresponds: return True, os.path.join(prod_dir, dir_or_file) @@ -410,6 +505,8 @@ def get_product_dependencies(config, product_info): return [] res = [] for prod in product_info.depend: + if prod == product_info.name: + continue if prod not in res: res.append(prod) prod_info = get_product_config(config, prod) @@ -427,7 +524,9 @@ def check_installation(product_info): the product :return: True if it is well installed :rtype: boolean - ''' + ''' + if not product_compiles(product_info): + return True install_dir = product_info.install_dir if not os.path.exists(install_dir): return False @@ -454,18 +553,16 @@ def product_is_sample(product_info): return False def product_is_salome(product_info): - '''Know if a product is of type salome + '''Know if a product is a SALOME module :param product_info Config: The configuration specific to the product - :return: True if the product is salome, else False + :return: True if the product is a SALOME module, else False :rtype: boolean ''' - if 'type' in product_info: - ptype = product_info.type - return ptype.lower() == 'salome' - else: - return False + return ("properties" in product_info and + "is_SALOME_module" in product_info.properties and + product_info.properties.is_SALOME_module == "yes") def product_is_fixed(product_info): '''Know if a product is fixed @@ -543,18 +640,6 @@ def product_is_vcs(product_info): ''' return product_info.get_source in AVAILABLE_VCS -def product_is_SALOME(product_info): - '''Know if a product is a SALOME module - - :param product_info Config: The configuration specific to - the product - :return: True if the product is a SALOME module, else False - :rtype: boolean - ''' - return ("properties" in product_info and - "is_SALOME_module" in product_info.properties and - product_info.properties.is_SALOME_module == "yes") - def product_is_smesh_plugin(product_info): '''Know if a product is a SMESH plugin @@ -579,6 +664,19 @@ def product_is_cpp(product_info): "cpp" in product_info.properties and product_info.properties.cpp == "yes") +def product_compiles(product_info): + '''Know if a product compiles or not (some products do not have a + compilation procedure) + + :param product_info Config: The configuration specific to + the product + :return: True if the product compiles, else False + :rtype: boolean + ''' + return not("properties" in product_info and + "compilation" in product_info.properties and + product_info.properties.compilation == "no") + def product_has_script(product_info): '''Know if a product has a compilation script @@ -627,6 +725,18 @@ def product_has_logo(product_info): else: return False +def product_has_salome_gui(product_info): + '''Know if a product has a SALOME gui + + :param product_info Config: The configuration specific to + the product + :return: True if the product has a SALOME gui, else False + :rtype: Boolean + ''' + return ("properties" in product_info and + "has_salome_gui" in product_info.properties and + product_info.properties.has_salome_gui == "yes") + def product_is_mpi(product_info): '''Know if a product has openmpi in its dependencies @@ -646,8 +756,8 @@ def product_is_generated(product_info): :rtype: boolean ''' return ("properties" in product_info and - "generated" in product_info.properties and - product_info.properties.generated == "yes") + "generate" in product_info.properties and + product_info.properties.generate == "yes") def get_product_components(product_info): '''Get the component list to generate with the product @@ -668,4 +778,4 @@ def get_product_components(product_info): if isinstance(compo_list, str): compo_list = [ compo_list ] - return compo_list \ No newline at end of file + return compo_list