[GRASS-SVN] r46587 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 7 12:27:56 EDT 2011


Author: martinl
Date: 2011-06-07 09:27:56 -0700 (Tue, 07 Jun 2011)
New Revision: 46587

Modified:
   grass/trunk/gui/wxpython/gui_modules/preferences.py
Log:
wxGUI/preferences: minor clean-up of _readFile()


Modified: grass/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-06-07 16:20:37 UTC (rev 46586)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2011-06-07 16:27:56 UTC (rev 46587)
@@ -697,20 +697,22 @@
 
         @param filename settings file path
         @param settings dict where to store settings (None for self.userSettings)
-        
-        @return True on success
-        @return False on failure
         """
         if settings is None:
             settings = self.userSettings
-
+        
         if not os.path.exists(filename):
-            return False
+            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:]
@@ -730,16 +732,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()
-            return False
+                                   "\t\tDetails: %(detail)s\n"
+                                   "\t\tLine: '%(line)s'\n") % { 'file' : filename,
+                                                               'detail' : e,
+                                                               'line' : line }
+            fd.close()
         
-        file.close()
-        return True
-
+        fd.close()
+        
     def SaveToFile(self, settings = None):
         """!Save settings to the file"""
         if settings is None:



More information about the grass-commit mailing list