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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 1 03:51:54 EDT 2011


Author: martinl
Date: 2011-07-01 00:51:54 -0700 (Fri, 01 Jul 2011)
New Revision: 46889

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: clean up savings settings
      change default location to .grass6/wx (still reading old location)
      (merge r46887 & r46888 from devbr6)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2011-07-01 07:50:15 UTC (rev 46888)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/gselect.py	2011-07-01 07:51:54 UTC (rev 46889)
@@ -1048,9 +1048,9 @@
             self.sourceMap['pro'] = idx
         
         if self.ogr:
-            self.settingsFile = os.path.join(os.path.expanduser("~"), '.grass7', 'wxOGR')
+            self.settingsFile = os.path.join(utils.GetSettingsPath(), 'wxOGR')
         else:
-            self.settingsFile = os.path.join(os.path.expanduser("~"), '.grass7', 'wxGDAL')
+            self.settingsFile = os.path.join(utils.GetSettingsPath(), 'wxGDAL')
         
         self._settings = self._loadSettings()
         self.settingsChoice = wx.Choice(parent = self, id = wx.ID_ANY)

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py	2011-07-01 07:50:15 UTC (rev 46888)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/preferences.py	2011-07-01 07:51:54 UTC (rev 46889)
@@ -61,7 +61,7 @@
     """!Generic class where to store settings"""
     def __init__(self):
         # settings file
-        self.filePath = os.path.join(os.path.expanduser("~"), '.grasswx6')
+        self.filePath = os.path.join(utils.GetSettingsPath(), 'wx')
         
         # key/value separator
         self.sep = ';'
@@ -702,7 +702,10 @@
             settings = self.userSettings
         
         if not os.path.exists(filename):
-            return
+            # try alternative path
+            filename = os.path.join(os.path.expanduser("~"), '.grasswx6')
+            if not os.path.exists(filename):
+                return
         
         try:
             fd = open(filename, "r")
@@ -744,7 +747,15 @@
         """!Save settings to the file"""
         if settings is None:
             settings = self.userSettings
-                
+        
+        dirPath = utils.GetSettingsPath()
+        if not os.path.exists(dirPath):
+            try:
+                os.mkdir(dirPath)
+            except:
+                gcmd.GError(_('Unable to create settings directory'))
+                return
+        
         try:
             file = open(self.filePath, "w")
             for group in settings.keys():

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py	2011-07-01 07:50:15 UTC (rev 46888)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/utils.py	2011-07-01 07:51:54 UTC (rev 46889)
@@ -752,3 +752,12 @@
             }
     
     return formats
+
+def GetSettingsPath():
+    """!Get full path to the settings directory
+    """
+    version = int(grass.version()['version'].split('.', 1)[0])
+    if sys.platform == 'win32':
+        return os.path.join(os.getenv('APPDATA'), '.grass%d' % version)
+    
+    return os.path.join(os.getenv('HOME'), '.grass%d' % version)



More information about the grass-commit mailing list