Prechádzať zdrojové kódy

wxGUI: recover original cmdfile

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@47001 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 14 rokov pred
rodič
commit
8a9c0e3546
1 zmenil súbory, kde vykonal 18 pridanie a 3 odobranie
  1. 18 3
      gui/wxpython/gui_modules/render.py

+ 18 - 3
gui/wxpython/gui_modules/render.py

@@ -25,6 +25,7 @@ import glob
 import math
 import copy
 import tempfile
+import stat
 
 import wx
 from wx.lib.newevent import NewEvent
@@ -855,9 +856,11 @@ class Map(object):
         """!Parse cmd file for standalone application
         """
         try:
+            cmdTimestamp = os.path.getmtime(self.cmdfile)
             fd = open(self.cmdfile, 'r')
             grass.try_remove(self.mapfile)
-            for cmd in fd.readlines():
+            cmdLines = fd.readlines()
+            for cmd in cmdLines:
                 cmdStr = cmd.strip().split(' ')
                 cmd = utils.CmdToTuple(cmdStr)
                 
@@ -867,10 +870,22 @@ class Map(object):
                               (self.cmdfile, e))
             return
         
-        Debug.msg(1, "Map.__parseCmdFile(): cmdfile=%s" % self.cmdfile)
-        Debug.msg(1, "                      nlayers=%d" % len(self.layers))
+        fd.close()
+        
+        # recover original cmdfile
+        try:
+            fd = open(self.cmdfile, 'w')
+            fd.writelines(cmdLines)
+            
+        except IOError, e:
+            grass.warning(_("Unable to recover cmdfile '%s'. Details: %s") % \
+                              (self.cmdfile, e))  
         
         fd.close()
+        os.utime(self.cmdfile, (os.stat(self.cmdfile)[stat.ST_ATIME], cmdTimestamp))
+
+        Debug.msg(1, "Map.__parseCmdFile(): cmdfile=%s" % self.cmdfile)
+        Debug.msg(1, "                      nlayers=%d" % len(self.layers))
         
     def _renderCmdFile(self, force, windres):
         if not force: