[GRASS-SVN] r73417 - grass/trunk/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 26 13:37:41 PDT 2018


Author: martinl
Date: 2018-09-26 13:37:41 -0700 (Wed, 26 Sep 2018)
New Revision: 73417

Modified:
   grass/trunk/gui/wxpython/gui_core/goutput.py
   grass/trunk/gui/wxpython/gui_core/prompt.py
Log:
Command prompt - Log files produces empty log files, see #3657

Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py	2018-09-26 19:18:37 UTC (rev 73416)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py	2018-09-26 20:37:41 UTC (rev 73417)
@@ -173,6 +173,7 @@
             size=self.btnCmdClear.GetSize())
         self.btnCmdProtocol.SetToolTip(_("Toggle to save list of executed commands into "
                                          "a file; content saved when switching off."))
+        self.cmdFileProtocol = None
 
         if not self._gcstyle & GC_PROMPT:
             self.btnCmdClear.Hide()
@@ -484,24 +485,23 @@
 
     def CmdProtocolSave(self):
         """Save list of manually entered commands into a text log file"""
-        if not hasattr(self, 'cmdFileProtocol'):
+        if self.cmdFileProtocol is None:
             return  # it should not happen
 
         try:
-            output = open(self.cmdFileProtocol, "a")
-            cmds = self.cmdPrompt.GetCommands()
-            output.write('\n'.join(cmds))
-            if len(cmds) > 0:
-                output.write('\n')
+            with open(self.cmdFileProtocol, "a") as output:
+                cmds = self.cmdPrompt.GetCommands()
+                output.write(os.linesep.join(cmds))
+                if len(cmds) > 0:
+                    output.write(os.linesep)
         except IOError as e:
-            GError(_("Unable to write file '%(filePath)s'.\n\nDetails: %(error)s") %
-                   {'filePath': self.cmdFileProtocol, 'error': e})
-        finally:
-            output.close()
+            GError(_("Unable to write file '{filePath}'.\n\nDetails: {error}").format(
+                filePath=self.cmdFileProtocol, error=e))
 
-        message = _("Command log saved to '%s'") % self.cmdFileProtocol
-        self.showNotification.emit(message=message)
-        del self.cmdFileProtocol
+        self.showNotification.emit(
+            message=_("Command log saved to '{}'".format(self.cmdFileProtocol))
+        )
+        self.cmdFileProtocol = None
 
     def OnCmdProtocol(self, event=None):
         """Save commands into file"""

Modified: grass/trunk/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/prompt.py	2018-09-26 19:18:37 UTC (rev 73416)
+++ grass/trunk/gui/wxpython/gui_core/prompt.py	2018-09-26 20:37:41 UTC (rev 73417)
@@ -111,8 +111,6 @@
         if not cmdString:
             return
 
-        self.commands.append(cmdString)  # trace commands
-
         # parse command into list
         try:
             cmd = utils.split(str(cmdString))
@@ -122,8 +120,6 @@
 
         self.promptRunCmd.emit(cmd=cmd)
 
-        # add command to history & clean prompt
-        # self.UpdateCmdHistory(cmd)
         self.OnCmdErase(None)
         self.ShowStatusText('')
 
@@ -300,6 +296,8 @@
         """
         # add command to history
         self.cmdbuffer.append(cmd)
+        # update also traced commands
+        self.commands.append(cmd)
 
         # keep command history to a managable size
         if len(self.cmdbuffer) > 200:



More information about the grass-commit mailing list