Salome HOME
gestion de path multiples dans la configuration projet
[tools/sat.git] / src / salomeTools.py
index 139e3cc2dc9d090aa3d47b247b00f696ce00e75b..a49524b24c465199efc051015dc06bed564dd2f7 100755 (executable)
@@ -65,7 +65,10 @@ import commands.config as CONFIG
 # load resources for internationalization
 gettext.install("salomeTools", os.path.join(srcdir, "i18n"))
 
-_LANG = os.environ["LANG"] # original locale
+try:
+  _LANG = os.environ["LANG"] # original locale
+except:
+  _LANG = "en_US.utf8" #default
 
 # The possible hooks : 
 # pre is for hooks to be executed before commands
@@ -86,9 +89,9 @@ parser.add_option('v', 'verbose', 'int', "output_verbose_level",
 parser.add_option('b', 'batch', 'boolean', "batch", 
                   _("batch mode (no question)."))
 parser.add_option('t', 'all_in_terminal', 'boolean', "all_in_terminal", 
-                  _("All traces in the terminal (for example compilation logs)."))
+                  _("all traces in the terminal (for example compilation logs)."))
 parser.add_option('l', 'logs_paths_in_file', 'string', "logs_paths_in_file", 
-                  _("Put the command result and paths to log files in ."))
+                  _("put the command results and paths to log files."))
 
 
 ########################################################################
@@ -231,11 +234,14 @@ class Sat(object):
     def setInternals(self, opt=None, datadir=None):
         """set the commands by calling the dedicated function etc..."""
         options, remaindersArgs = parser.parse_args(opt)
+        if options.debug_mode:
+            DBG.push_debug(True)
         self.arguments = opt
         self.options = options # the generic options passed to salomeTools
         self.remaindersArgs = remaindersArgs  # the command and their options
         self.datadir = datadir # default value will be <salomeTools root>/data
         self._setCommands(cmdsdir)
+        DBG.write("Sat.options", self.options, self.options.debug_mode)
 
     def getConfig(self):
         return self.cfg
@@ -342,7 +348,6 @@ class Sat(object):
         '''
         # loop on the commands name
         for nameCmd in lCommand:
-            DBG.write("load module command '%s.py'" % nameCmd, "")
             # Exception for the jobs command that requires the paramiko module
             if nameCmd == "jobs":
                 try:
@@ -458,7 +463,12 @@ class Sat(object):
                                              src.printcolors.printcWarning(msg),
                                              str(e)))
                         self.options.logs_paths_in_file = None
-                
+
+
+                # do nothing more if help is True
+                if self.options.help:
+                  return 0
+
                 options_launched = ""
                 res = None
                 try:
@@ -470,23 +480,25 @@ class Sat(object):
                     if res is None:
                         res = 0
                         
-                except Exception as e:
-                    # Get error
+                except src.SatException as e:
+                    # for sat exception do not display the stack, unless debug mode is set
                     logger_command.write("\n***** ", 1)
                     logger_command.write(src.printcolors.printcError(
-                                                       "salomeTools ERROR:"), 1)
-                    logger_command.write("\n" + str(e) + "\n\n", 1)
-                    # get stack
-                    __, __, exc_traceback = sys.exc_info()
-                    fp = tempfile.TemporaryFile()
-                    traceback.print_tb(exc_traceback, file=fp)
-                    fp.seek(0)
-                    stack = fp.read()
-                    verbosity = 5
+                            "salomeTools ERROR: sat %s" % __nameCmd__), 1)
+                    logger_command.write(" *****\n", 1)
+                    print(e.message)
                     if self.options.debug_mode:
-                        verbosity = 1
-                    logger_command.write("TRACEBACK: %s" % stack.replace('"',"'"),
-                                         verbosity)
+                        logger_command.write("\n" + DBG.format_exception("") + "\n", 1)
+
+                except Exception as e:
+                    # here we print the stack in addition
+                    logger_command.write("\n***** ", 1)
+                    logger_command.write(src.printcolors.printcError(
+                            "salomeTools ERROR: sat %s" % __nameCmd__), 1)
+
+                    logger_command.write("\n" + DBG.format_exception("") + "\n", 1)
+
+
                 finally:
                     # set res if it is not set in the command
                     if res is None:
@@ -515,6 +527,7 @@ class Sat(object):
                                                 options_launched,
                                                 __nameCmd__, 
                                                 ' '.join(argv_0)])
+                    # TODO may be no need as call escapeSequence xml
                     launchedCommand = launchedCommand.replace('"', "'")
                     
                     # Add a link to the parent command      
@@ -692,7 +705,7 @@ def get_version():
     cfgManager = CONFIG.ConfigManager()
     cfg = cfgManager.get_config()
     # print the key corresponding to salomeTools version
-    msg = (src.printcolors.printcHeader( _("Version: ") ) + cfg.INTERNAL.sat_version)
+    msg = (src.printcolors.printcHeader( _("Version: ") ) + src.get_salometool_version(cfg))
     return msg
 
 
@@ -703,7 +716,7 @@ def get_help():
     '''
     msg = "\n" + get_version() + "\n\n"
     msg += src.printcolors.printcHeader( _("Usage: ") ) + \
-          "sat [sat_options] <command> [product] [command_options]\n\n"
+          "sat [sat_options] <command> [application] [command_options]\n\n"
 
     msg += parser.get_help() + "\n"
 
@@ -715,7 +728,7 @@ def get_help():
     msg += "\n"
     # Explain how to get the help for a specific command
     msg += src.printcolors.printcHeader(
-        _("Getting the help for a specific command: ")) + \
+        _("Get help for a specific command:")) + \
         "\n>> sat --help <command>\n"
     return msg