[GRASS-SVN] r46586 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 7 12:20:37 EDT 2011


Author: martinl
Date: 2011-06-07 09:20:37 -0700 (Tue, 07 Jun 2011)
New Revision: 46586

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py
Log:
bugfix #1383 (wxGUI crashes if settings file .grasswx6 does not exist)
       (merge r46585 from devbr6)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py	2011-06-07 16:15:26 UTC (rev 46585)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py	2011-06-07 16:20:37 UTC (rev 46586)
@@ -693,11 +693,19 @@
         """!Read settings from file to dict"""
         if settings is None:
             settings = self.userSettings
-
+        
+        if not os.path.exists(filename):
+            return
+        
         try:
-            file = open(filename, "r")
+            fd = open(filename, "r")
+        except IOError:
+            sys.stderr.write(_("Unable to read settings file <%s>\n") % filename)
+            return
+        
+        try:
             line = ''
-            for line in file.readlines():
+            for line in fd.readlines():
                 line = line.rstrip('%s' % os.linesep)
                 group, key = line.split(self.sep)[0:2]
                 kv = line.split(self.sep)[2:]
@@ -717,14 +725,14 @@
                     idx += 2
         except ValueError, e:
             print >> sys.stderr, _("Error: Reading settings from file <%(file)s> failed.\n"
-                                   "       Details: %(detail)s\n"
-                                   "       Line: '%(line)s'") % { 'file' : filename,
-                                                                  'detail' : e,
-                                                                  'line' : line }
-            file.close()
+                                   "\t\tDetails: %(detail)s\n"
+                                   "\t\tLine: '%(line)s'\n") % { 'file' : filename,
+                                                                 'detail' : e,
+                                                                 'line' : line }
+            fd.close()
+        
+        fd.close()
 
-        file.close()
-
     def SaveToFile(self, settings = None):
         """!Save settings to the file"""
         if settings is None:



More information about the grass-commit mailing list