Salome HOME
sat #18867 : pour les url des bases git : substitution des references par leur valeur...
[tools/sat.git] / commands / config.py
index 0e1c1a3f70ce3deebb738973cf82e619c278ba4e..6ef3dbff7dce1326f5c8b457c376dad81a44d3f3 100644 (file)
@@ -57,6 +57,8 @@ parser.add_option('', 'show_install', 'boolean', 'show_install',
     _("Optional: synthetic list of all install directories in the application"))
 parser.add_option('', 'show_properties', 'boolean', 'show_properties',
     _("Optional: synthetic list of all properties used in the application"))
+parser.add_option('', 'check_system', 'boolean', 'check_system',
+    _("Optional: check if system products are installed"))
 parser.add_option('c', 'copy', 'boolean', 'copy',
     _("""Optional: copy a config file to the personal config files directory.
 WARNING: the included files are not copied.
@@ -261,8 +263,12 @@ class ConfigManager:
         src.pyconf.streamOpener = ConfigOpener([
                              osJoin(cfg.VARS.srcDir, 'internal_config')])
         try:
-            internal_cfg = src.pyconf.Config(open( osJoin(cfg.VARS.srcDir,
-                                    'internal_config', 'salomeTools.pyconf')))
+            if src.architecture.is_windows(): # special internal config for windows
+                internal_cfg = src.pyconf.Config(open( osJoin(cfg.VARS.srcDir,
+                                        'internal_config', 'salomeTools_win.pyconf')))
+            else:
+                internal_cfg = src.pyconf.Config(open( osJoin(cfg.VARS.srcDir,
+                                        'internal_config', 'salomeTools.pyconf')))
         except src.pyconf.ConfigError as e:
             raise src.SatException(_("Error in configuration file:"
                                      " salomeTools.pyconf\n  %(error)s") % \
@@ -303,7 +309,7 @@ class ConfigManager:
             cfg.LOCAL.archive_dir = os.path.abspath( osJoin(cfg.VARS.salometoolsway, "..", "ARCHIVES"))
 
         # if the sat tag was not set permanently by user
-        if cfg.LOCAL.tag == None:
+        if cfg.LOCAL.tag == "unknown":
             # get the tag with git, and store it
             sat_version=src.system.git_describe(cfg.VARS.salometoolsway) 
             if sat_version == False:
@@ -523,6 +529,8 @@ class ConfigManager:
         if "APPLICATION" in cfg and "rm_products" in cfg.APPLICATION:
             for prod_to_remove in cfg.APPLICATION.rm_products:
                 cfg.APPLICATION.products.__delitem__(prod_to_remove)
+            # remove rm_products section after usage
+            cfg.APPLICATION.__delitem__("rm_products")
         return cfg
 
     def set_user_config_file(self, config):
@@ -641,6 +649,10 @@ def show_product_info(config, name, logger):
     if "opt_depend" in pinfo:
         src.printcolors.print_value(logger, "optional", sorted(pinfo.opt_depend), 2)
 
+    if "build_depend" in pinfo:
+        src.printcolors.print_value(logger, "build depend on", sorted(pinfo.build_depend), 2)
+
+
     # information on pyconf
     logger.write("\n", 2)
     logger.write(src.printcolors.printcLabel("configuration:") + "\n", 2)
@@ -731,6 +743,12 @@ def show_product_info(config, name, logger):
             logger.write("  " + 
                          src.printcolors.printcWarning(_("no install dir")) + 
                          "\n", 2)
+
+        src.printcolors.print_value(logger, "debug ", pinfo.debug, 2)
+        src.printcolors.print_value(logger, "verbose ", pinfo.verbose, 2)
+        src.printcolors.print_value(logger, "hpc ", pinfo.hpc, 2)
+        src.printcolors.print_value(logger, "dev ", pinfo.dev, 2)
+
     else:
         logger.write("\n", 2)
         msg = _("This product does not compile")
@@ -778,6 +796,61 @@ def show_patchs(config, logger):
   else:
     logger.write("No patchs found\n", 1)
 
+def check_install_system(config, logger):
+  '''Check the installation of all (declared) system products
+
+  :param config Config: the global configuration.
+  :param logger Logger: The logger instance to use for the display
+  '''
+  # get the command to use for checking the system dependencies
+  # (either rmp or apt)
+  check_cmd=src.system.get_pkg_check_cmd(config.VARS.dist_name)
+  logger.write("\nCheck the system dependencies declared in the application\n",1)
+  pkgmgr=check_cmd[0]
+  run_dep_ko=[] # list of missing run time dependencies
+  build_dep_ko=[] # list of missing compile time dependencies
+  for product in sorted(config.APPLICATION.products):
+    try:
+      product_info = src.product.get_product_config(config, product)
+      if src.product.product_is_native(product_info):
+        # if the product is native, get (in two dictionnaries the runtime and compile time 
+        # system dependencies with the status (OK/KO)
+        run_pkg,build_pkg=src.product.check_system_dep(check_cmd, product_info)
+        #logger.write("\n*** %s ***\n" % product, 1)
+        for pkg in run_pkg:
+            logger.write("\n   - "+pkg + " : " + run_pkg[pkg], 1)
+            if "KO" in run_pkg[pkg]:
+                run_dep_ko.append(pkg)
+        for pkg in build_pkg:
+            logger.write("\n   - "+pkg + " : " + build_pkg[pkg], 1)
+            if "KO" in build_pkg[pkg]:
+                build_dep_ko.append(pkg)
+        #  logger.write(src.printcolors.printcInfo("    %s\n" % i), 1)
+
+    except Exception as e:
+      msg = "\nproblem with the check of system prerequisite %s\n%s\n" % (product, str(e))
+      logger.error(msg)
+      raise Exception(msg)
+
+  logger.write("\n\n",1)
+  if run_dep_ko:
+      msg="Some run time system dependencies are missing!\n"+\
+          "Please install them with %s before running salome" % pkgmgr
+      logger.warning(msg)
+      logger.write("missing run time dependencies : ",1)
+      for md in run_dep_ko: 
+        logger.write(md+" ",1)
+      logger.write("\n\n")
+        
+  if build_dep_ko:
+      msg="Some compile time system dependencies are missing!\n"+\
+          "Please install them with %s before compiling salome" % pkgmgr
+      logger.warning(msg)
+      logger.write("missing compile time dependencies : ",1)
+      for md in build_dep_ko: 
+        logger.write(md+" ",1)
+      logger.write("\n\n")
+    
 
 def show_install_dir(config, logger):
   '''Prints all the used installed directories in the application.
@@ -806,18 +879,23 @@ def show_properties(config, logger):
   :param config Config: the global configuration.
   :param logger Logger: The logger instance to use for the display
   '''
+  if "properties" in config.APPLICATION:
+      # some properties are defined at application level, we display them
+      logger.write("Application properties:\n", 1)
+      for prop in config.APPLICATION.properties:
+          logger.write(src.printcolors.printcInfo("    %s : %s\n" % (prop, config.APPLICATION.properties[prop])), 1)
   oneOrMore = False
   for product in sorted(config.APPLICATION.products):
     try:
       product_info = src.product.get_product_config(config, product)
       done = False
       try:
-        for i in product_info.properties:
+        for prop in product_info.properties:
           if not done:
             logger.write("%s:\n" % product, 1)
             done = True
           oneOrMore = True
-          logger.write(src.printcolors.printcInfo("    %s\n" % i), 1)
+          logger.write(src.printcolors.printcInfo("    %s : %s\n" % (prop, product_info.properties[prop])), 1)
       except Exception as e:
         pass
     except Exception as e:
@@ -1127,9 +1205,14 @@ def run(args, runner, logger):
     # case : give a synthetic view of all patches used in the application
     if options.show_properties:
         src.check_config_has_application(runner.cfg)
+
         # Print some informations
         logger.write(_('Properties of application %s\n') %
                     src.printcolors.printcLabel(runner.cfg.VARS.application), 3)
         logger.write("\n", 2, False)
         show_properties(runner.cfg, logger)
 
+    # check system prerequisites
+    if options.check_system:
+       check_install_system(runner.cfg, logger)
+       pass