[GRASS-SVN] r46887 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 1 03:45:57 EDT 2011


Author: martinl
Date: 2011-07-01 00:45:56 -0700 (Fri, 01 Jul 2011)
New Revision: 46887

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: clean up savings settings
       change default location to .grass6/wx (still reading old location)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2011-07-01 07:38:59 UTC (rev 46886)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2011-07-01 07:45:56 UTC (rev 46887)
@@ -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/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2011-07-01 07:38:59 UTC (rev 46886)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2011-07-01 07:45:56 UTC (rev 46887)
@@ -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/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2011-07-01 07:38:59 UTC (rev 46886)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2011-07-01 07:45:56 UTC (rev 46887)
@@ -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