[GRASS-SVN] r73420 - grass/branches/releasebranch_7_6/gui/wxpython/gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Sep 26 13:45:47 PDT 2018


Author: martinl
Date: 2018-09-26 13:45:47 -0700 (Wed, 26 Sep 2018)
New Revision: 73420

Modified:
   grass/branches/releasebranch_7_6/gui/wxpython/gui_core/goutput.py
   grass/branches/releasebranch_7_6/gui/wxpython/gui_core/prompt.py
Log:
Command prompt - Log files produces empty log files, see #3657 (g76: merge r73417 from trunk)

Modified: grass/branches/releasebranch_7_6/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/branches/releasebranch_7_6/gui/wxpython/gui_core/goutput.py	2018-09-26 20:40:01 UTC (rev 73419)
+++ grass/branches/releasebranch_7_6/gui/wxpython/gui_core/goutput.py	2018-09-26 20:45:47 UTC (rev 73420)
@@ -172,6 +172,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()
@@ -483,24 +484,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/branches/releasebranch_7_6/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/branches/releasebranch_7_6/gui/wxpython/gui_core/prompt.py	2018-09-26 20:40:01 UTC (rev 73419)
+++ grass/branches/releasebranch_7_6/gui/wxpython/gui_core/prompt.py	2018-09-26 20:45:47 UTC (rev 73420)
@@ -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