Salome HOME
sat #10567 : suppression doublon product_is_salome
[tools/sat.git] / src / logger.py
index 843f7b7a6ab5a69f0f7cd29c97d3f4b8ffc13261..48c6633573c17cc19ced3931c826a793f977e13c 100644 (file)
@@ -22,6 +22,7 @@ import sys
 import os
 import datetime
 import re
+import tempfile
 
 import src
 from . import printcolors
@@ -83,7 +84,17 @@ class Logger(object):
                             attrib = {"application" : config.VARS.application})
         self.put_initial_xml_fields()
         # Initialize the txt file for reading
-        self.logTxtFile = open(str(self.txtFilePath), 'w')
+        try:
+            self.logTxtFile = open(str(self.txtFilePath), 'w')
+        except IOError:
+            #msg1 = _("WARNING! Trying to write to a file that"
+            #         " is not accessible:")
+            #msg2 = _("The logs won't be written.")
+            #print("%s\n%s\n%s\n" % (src.printcolors.printcWarning(msg1),
+            #                        src.printcolors.printcLabel(str(self.txtFilePath)),
+            #                        src.printcolors.printcWarning(msg2) ))
+            self.logTxtFile = tempfile.TemporaryFile()
+            
         # If the option all_in_terminal was called, all the system commands
         # are redirected to the terminal
         if all_in_terminal:
@@ -237,10 +248,12 @@ class Logger(object):
                                 + self.config.VARS.command 
                                 + ".pyconf")
         dumpedPyconfFilePath = os.path.join(logDir, 'OUT', dumpedPyconfFileName)
-        f = open(dumpedPyconfFilePath, 'w')
-        self.config.__save__(f)
-        f.close()
-        
+        try:
+            f = open(dumpedPyconfFilePath, 'w')
+            self.config.__save__(f)
+            f.close()
+        except IOError:
+            pass
 
 def date_to_datetime(date):
     '''Little method that gets year, mon, day, hour , 
@@ -385,4 +398,4 @@ def update_hat_xml(logDir, application=None, notShownCommands = []):
                                              "full_command" : full_cmd})
     
     # Write the file on the hard drive
-    xmlHat.write_tree('hat.xsl')
\ No newline at end of file
+    xmlHat.write_tree('hat.xsl')