+def get_product_section(config, product_name, version, section=None, verbose=False):
+ """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 as 'V8_4_0', or else.
+ :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
+ aProd = config.PRODUCTS[product_name]
+ try:
+ versionMMP = VMMP.MinorMajorPatch(version)
+ except: # example setuptools raise "minor in major_minor_patch is not integer: '0_6c11'"
+ versionMMP = None
+ DBG.write("get_product_section for product %s '%s' as version '%s'" % (product_name, version, versionMMP),
+ (section, aProd.keys()), verbose)
+ # DBG.write("yoo1", aProd, True)
+ if section:
+ if section not in aProd:
+ return None
+ # returns specific information for the given version
+ prod_info = aProd[section]
+ prod_info.section = section
+ prod_info.from_file = aProd.from_file
+ return prod_info
+
+ # If it exists, get the information of the product_version
+ # ex: 'version_V6_6_0' as salome version classical syntax
+ if "version_" + version in aProd:
+ DBG.write("found section for version_" + version, "", verbose)
+ # returns specific information for the given version
+ prod_info = aProd["version_" + version]
+ prod_info.section = "version_" + version
+ prod_info.from_file = aProd.from_file
+ return prod_info
+
+ # Else, check if there is a description for multiple versions
+ l_section_names = aProd.keys()
+ l_section_ranges = []
+ tagged = []
+ for name in l_section_names:
+ # DBG.write("name", name,True)
+ aRange = VMMP.getRange_majorMinorPatch(name)
+ if aRange is not None:
+ DBG.write("found version range for section '%s'" % name, aRange, verbose)
+ l_section_ranges.append((name, aRange))
+
+ if versionMMP is not None and len(l_section_ranges) > 0:
+ for name, (vmin, vmax) in l_section_ranges:
+ if versionMMP >= vmin and versionMMP <= vmax:
+ tagged.append((name, [vmin, vmax]))
+
+ if len(tagged) > 1:
+ DBG.write("multiple version ranges tagged for '%s', fix it" % version,
+ PP.pformat(tagged), True)
+ return None
+ if len(tagged) == 1: # ok
+ DBG.write("one version range tagged for '%s'" % version,
+ PP.pformat(tagged), verbose)
+ name, (vmin, vmax) = tagged[0]
+ prod_info = aProd[name]
+ prod_info.section = name
+ prod_info.from_file = aProd.from_file
+ return prod_info
+
+ # Else, get the standard informations
+ if "default" in aProd:
+ # returns the generic information (given version not found)
+ prod_info = aProd.default
+ DBG.write("default tagged for '%s'" % version, prod_info, verbose)
+ prod_info.section = "default"
+ prod_info.from_file = aProd.from_file
+ return prod_info
+
+ # if noting was found, return None
+ return None
+