]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
fix commands/config.py sat config -l
authorChristian Van Wambeke <christian.van-wambeke@cea.fr>
Tue, 3 Apr 2018 14:41:10 +0000 (16:41 +0200)
committerChristian Van Wambeke <christian.van-wambeke@cea.fr>
Tue, 3 Apr 2018 14:41:10 +0000 (16:41 +0200)
commands/application.py
commands/config.py
commands/package.py
sat
src/configManager.py
src/options.py
src/product.py

index 6c891ac86983862de3568bcc24c0dff87c29ae34..f14ff0d4218351284820e02136d4c851ac63190a 100644 (file)
@@ -94,15 +94,14 @@ NOTICE:   this command will ssh to retrieve information to each machine in the l
     # check for product
     src.check_config_has_application( runner.cfg )
 
-    application = src.printcolors.printcLabel(runner.cfg.VARS.application)
-    logger.write(_("Building application for %s\n") % application, 1)
+    application = runner.cfg.VARS.application
+    logger.info(_("Building application for <header>%s<reset>\n") % application)
 
     # if section APPLICATION.virtual_app does not exists create one
     if "virtual_app" not in runner.cfg.APPLICATION:
         msg = _("The section APPLICATION.virtual_app is not defined in the product.")
-        logger.write(src.printcolors.printcError(msg), 1)
-        logger.write("\n", 1)
-        return 1
+        logger.info("red>" + msg + "<reset>" )
+        return RCO.ReturnCode("KO", msg)
 
     # get application dir
     target_dir = runner.cfg.APPLICATION.workdir
index 489375cae18c8744f860a52fe34b8a352af87df1..6db06c75776123af0962d60f359f1cb3e629ab3e 100644 (file)
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
+import os
 
 import src.debug as DBG
 import src.returnCode as RCO
 from src.salomeTools import _BaseCommand
+import src.configManager as CFGMGR
 
 
 ########################################################################
@@ -58,9 +60,10 @@ class Command(_BaseCommand):
     parser.add_option('p', 'show_patchs', 'boolean', 'show_patchs',
         _("Optional: synthetic view of all patches used in the application"))
     parser.add_option('c', 'copy', 'boolean', 'copy',
-        _("""Optional: copy a config file (.pyconf) to the personal config files directory.
-      Warning: the included files are not copied.
-      If a name is given the new config file takes the given name."""))
+        _("""\
+Optional: copy a config file (.pyconf) to the personal config files directory.
+Warning: the included files are not copied.
+If a name is given the new config file takes the given name."""))
     parser.add_option('n', 'no_label', 'boolean', 'no_label',
         _("Internal use: do not print labels, Works only with --value and --list."))
     parser.add_option('o', 'completion', 'boolean', 'completion',
@@ -103,9 +106,9 @@ class Command(_BaseCommand):
         if options.value == ".":
             # if argument is ".", print all the config
             for val in sorted(config.keys()):
-                print_value(config, val, not options.no_label, logger)
+                CFGMGR.print_value(config, val, logger, not options.no_label)
         else:
-            print_value(config, options.value, not options.no_label, logger
+            CFGMGR.print_value(config, options.value, logger, not options.no_label
                         level=0, show_full_path=False)
 
     if options.debug:
@@ -191,11 +194,10 @@ class Command(_BaseCommand):
         for path in config.PATHS.APPLICATIONPATH:
             # print a header
             if not options.no_label:
-                logger.write("------ %s\n" % src.printcolors.printcHeader(path))
-
+                logger.info("<header>------ %s<reset>" % path)
+            msg = "" # only one multiline info
             if not os.path.exists(path):
-                logger.write(src.printcolors.printcError(
-                    _("Directory not found")) + "\n" )
+                msg += ("<red>" +  _("Directory not found") + "<reset>\n" )
             else:
                 for f in sorted(os.listdir(path)):
                     # ignore file that does not ends with .pyconf
@@ -207,11 +209,11 @@ class Command(_BaseCommand):
                         lproduct.append(appliname)
                         if path.startswith(config.VARS.personalDir) \
                                     and not options.no_label:
-                            logger.write("%s*\n" % appliname)
+                            msg += "%s*\n" % appliname
                         else:
-                            logger.write("%s\n" % appliname)
+                            msg += "%s\n" % appliname
                             
-            logger.write("\n")
+            logger.info(msg)
 
     # case : give a synthetic view of all patches used in the application
     elif options.show_patchs:
index 868fa4825a51413b806738fad67f83a7444e5bd2..6d4d536f354a971fb6c4db66f24d4cf63a57c55e 100644 (file)
@@ -31,6 +31,7 @@ import src.debug as DBG
 import src.returnCode as RCO
 from src.salomeTools import _BaseCommand
 import src.pyconf as PYCONF
+import src.utilsSat as UTS
 
 BINARY = "binary"
 SOURCE = "Source"
@@ -1142,7 +1143,7 @@ def find_product_scripts_and_pyconf(p_name,
     '''
     
     # read the pyconf of the product
-    product_pyconf_path = src.find_file_in_lpath(p_name + ".pyconf",
+    product_pyconf_path = UTS.find_file_in_lpath(p_name + ".pyconf",
                                            config.PATHS.PRODUCTPATH)
     product_pyconf_cfg = PYCONF.Config(product_pyconf_path)
 
@@ -1204,7 +1205,7 @@ def find_application_pyconf(config, application_tmp_dir):
     '''
     # read the pyconf of the application
     application_name = config.VARS.application
-    application_pyconf_path = src.find_file_in_lpath(
+    application_pyconf_path = UTS.find_file_in_lpath(
                                             application_name + ".pyconf",
                                             config.PATHS.APPLICATIONPATH)
     application_pyconf_cfg = PYCONF.Config(application_pyconf_path)
diff --git a/sat b/sat
index 08eda1ced7775da343667e0a01e44bdd07bb17e0..6769e8ab4635f51296898f675a8c8d7b46d2c421 100755 (executable)
--- a/sat
+++ b/sat
@@ -59,13 +59,14 @@ if __name__ == "__main__":
       sys.exit(returnCode.toSys())
       
     except Exception as e:
-      msg = "Exception raised for execute_cli('%s'):\n\n<yellow>%s<reset>"
       if (_debug) or (DBG._user in DBG._developpers):
         # verbose debug message with traceback
+        msg = "Exception raised for execute_cli(%s):\n\n<yellow>%s<reset>"
         import traceback
         logger.critical( msg % (args, traceback.format_exc()) )
       else:
         # short production message
+        msg = "Exception raised for execute_cli(%s):\n\n<red>%s<reset>\n"
         logger.critical( msg % (args, e) )
       sys.exit(KOSYS)
 
index 2730434084f845c00075b1f769973076ae699068..91d5e139d781e156b3f80b76d0f9511737f00e76 100644 (file)
@@ -351,8 +351,8 @@ class ConfigManager:
             try:
                 application_cfg = PYCONF.Config(application + '.pyconf')
             except IOError as e:
-                raise Exception(_("%suse 'config --list' to get the"
-                                         " list of available applications.") % e)
+                raise Exception(_("%s\n(use 'config --list' to get the"
+                                         " list of available applications)") % e)
             except PYCONF.ConfigError as e:
                 if (not ('-e' in parser.parse_args()[1]) 
                                          or ('--edit' in parser.parse_args()[1]) 
@@ -394,7 +394,7 @@ class ConfigManager:
                 # Loop on all files that are in softsDir directory
                 # and read their config
                 product_file_name = product_name + ".pyconf"
-                product_file_path = src.find_file_in_lpath(product_file_name, cfg.PATHS.PRODUCTPATH)
+                product_file_path = UTS.find_file_in_lpath(product_file_name, cfg.PATHS.PRODUCTPATH)
                 if product_file_path:
                     products_dir = os.path.dirname(product_file_path)
                     try:
@@ -732,28 +732,26 @@ def getConfigColored(config, path, stream, show_label=False, level=0, show_full_
     try:
         val = config.getByPath(path)
     except Exception as e:
-        stream.write(tab_level)
-        stream.write("<header>%s: <red>ERROR %s<reset>\n" % (vname, str(e)))
+        stream.write(tab_level + "<header>%s: <red>ERROR %s<reset>\n" % (vname, str(e)))
         return
 
     # in this case, display only the value
     if show_label:
-        stream.write(tab_level)
-        stream.write("<header%s: <reset>" % vname)
+        stream.write(tab_level + "<header>%s: <reset>" % vname)
 
     # The case where the value has under values, 
     # do a recursive call to the function
     if dir(val).__contains__('keys'):
-        if show_label: strean.write("\n")
+        if show_label: stream.write("\n")
         for v in sorted(val.keys()):
-            print_value(config, path + '.' + v, stream, show_label, level + 1)
+            getConfigColored(config, path + '.' + v, stream, show_label, level + 1)
     elif val.__class__ == PYCONF.Sequence or isinstance(val, list): 
         # in this case, value is a list (or a Sequence)
         if show_label: stream.write("\n")
         index = 0
         for v in val:
             p = path + "[" + str(index) + "]"
-            print_value(config, p, stream, show_label, level + 1)
+            getConfigColored(config, p, stream, show_label, level + 1)
             index += 1
     else: # case where val is just a str
         stream.write("%s\n" % val)
@@ -764,10 +762,10 @@ def print_value(config, path, logger, show_label=False, level=0, show_full_path=
     used recursively from the initial path.
     
     :param see getConfigColored
-    """           
+    """ 
     outStream = DBG.OutStream()
     getConfigColored(config, path, outStream, show_label, level, show_full_path)
-    res = outStream.value
+    res = outStream.getvalue() # stream not closed
     logger.info(res)
     return
 
index 714fcc46c21dc02a5a340b90029d2e64affcf82e..57395bbb7da0363fd11a0bbc7cc87e7fb43334eb 100644 (file)
@@ -49,7 +49,7 @@ class OptResult(object):
         
         :param name str: The attribute to get the value.
         :return: the value corresponding to the attribute.
-        :rtype: str,int,list,boolean
+        :rtype: str,int,list,boolean,level
         '''
         if name in self.__dict__:
             return self.__dict__[name]
@@ -82,7 +82,7 @@ class Options(object):
         # in a list that contains dicts
         self.options = []
         # The list of available option type
-        self.availableOptions = "boolean string int float long list list2".split()
+        self.availableOptions = "boolean string int float long list list2, level".split()
         self.default = None
         self.results = {}
 
@@ -123,6 +123,17 @@ class Options(object):
         option['result'] = default
         
         self.options.append(option)
+        
+    def getDetailOption(self, option):
+        """for convenience 
+        returns (shortName, longName, optionType, helpString')
+        """
+        oos = option['shortName']
+        ool = option['longName']
+        oot = option['optionType']
+        ooh = option['helpString']
+        return (oos, ool, oot, ooh)
+
 
     def get_help(self):
         '''Method that returns all options stored in self.options 
@@ -137,17 +148,23 @@ class Options(object):
             return _("No available options.")
 
         # for all options, gets its values. 
-        # "shortname" is an optional field of the options 
-        msg += "<header>" + _("Available options are:") + "<reset>\n"
+        # "shortname" is an mandatory field of the options, could be '' 
+        msg += "<header>" + _("Available options are:") + "<reset>"
         for option in self.options:
-            if 'shortName' in option and len(option['shortName']) > 0:
-                msg +=  "\n -%(shortName)1s, --%(longName)s" \
-                        " (%(optionType)s)\n\t%(helpString)s\n" % option
+            oos, ool, oot, ooh = self.getDetailOption(option)
+            if len(oos) > 0:
+                msg += "\n -%1s, --%s (%s)\n" % (oos, ool, oot)
             else:
-                msg += "\n --%(longName)s (%(optionType)s)\n\t%(helpString)s\n" \
-                       % option
+                msg += "\n --%s (%s)\n" % (ool, oot)
+                
+            msg += "%s\n" % self.indent(ooh, 10)
         return msg
-                       
+        
+    def indent(self, text, amount, car=" "):
+        """indent multi lines message"""
+        padding = amount * car
+        return ''.join(padding + line for line in text.splitlines(True))
+               
 
     def parse_args(self, argList=None):
         '''Method that instantiates the class OptResult 
@@ -210,6 +227,9 @@ class Options(object):
                         if option['result'] is None:
                             option['result'] = list()
                         option['result'].append(opt[1])
+                    elif optionType == "level": #logger logging levels
+                        option['result'] = opt[1]
+                        # TODO test in (lowercase) debug info warning error critical
                     elif optionType == "list2":
                         if option['result'] is None:
                             option['result'] = list()
index 19bebd2ef19769834d57b94a1e4388bcb83a2968..df13ec21232c767b69fdba7ef6b67f51ce015e94 100644 (file)
@@ -23,6 +23,7 @@ import os
 import re
 
 import src.pyconf as PYCONF
+import src.utilsSat as UTS
 
 AVAILABLE_VCS = ['git', 'svn', 'cvs']
 config_expression = "^config-\d+$"
@@ -142,7 +143,7 @@ def get_product_config(config, product_name, with_install_dir=True):
     # 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:
-        prod_pyconf_path = src.find_file_in_lpath(product_name + ".pyconf",
+        prod_pyconf_path = UTS.find_file_in_lpath(product_name + ".pyconf",
                                                   config.PATHS.PRODUCTPATH)
         if not prod_pyconf_path:
             msg = _("""\
@@ -171,7 +172,7 @@ Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path}
                                  "")
         if "archive_name" not in prod_info.archive_info: 
             arch_name = product_name + "-" + version + ".tar.gz"
-            arch_path = src.find_file_in_lpath(arch_name,
+            arch_path = UTS.find_file_in_lpath(arch_name,
                                                config.PATHS.ARCHIVEPATH)
             if not arch_path:
                 msg = _("Archive %(1)s for %(2)s not found.\n") % \
@@ -182,7 +183,7 @@ Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path}
             if (os.path.basename(prod_info.archive_info.archive_name) == 
                                         prod_info.archive_info.archive_name):
                 arch_name = prod_info.archive_info.archive_name
-                arch_path = src.find_file_in_lpath(
+                arch_path = UTS.find_file_in_lpath(
                                             arch_name,
                                             config.PATHS.ARCHIVEPATH)
                 if not arch_path:
@@ -206,7 +207,7 @@ Please provide a 'compil_script' key in its definition.""") % product_name
         script_name = os.path.basename(script)
         if script == script_name:
             # Only a name is given. Search in the default directory
-            script_path = src.find_file_in_lpath(script_name,
+            script_path = UTS.find_file_in_lpath(script_name,
                                                  config.PATHS.PRODUCTPATH,
                                                  "compil_scripts")
             if not script_path:
@@ -231,7 +232,7 @@ Please provide a 'compil_script' key in its definition.""") % product_name
             # If only a filename, then search for the patch in the PRODUCTPATH
             if os.path.basename(patch_path) == patch_path:
                 # Search in the PRODUCTPATH/patches
-                patch_path = src.find_file_in_lpath(patch,
+                patch_path = UTS.find_file_in_lpath(patch,
                                                     config.PATHS.PRODUCTPATH,
                                                     "patches")
                 if not patch_path:
@@ -248,7 +249,7 @@ Please provide a 'compil_script' key in its definition.""") % product_name
         # in the PRODUCTPATH/env_scripts
         if os.path.basename(env_script_path) == env_script_path:
             # Search in the PRODUCTPATH/env_scripts
-            env_script_path = src.find_file_in_lpath(
+            env_script_path = UTS.find_file_in_lpath(
                                             prod_info.environ.env_script,
                                             config.PATHS.PRODUCTPATH,
                                             "env_scripts")