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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 21 18:47:38 EDT 2010


Author: martinl
Date: 2010-06-21 22:47:38 +0000 (Mon, 21 Jun 2010)
New Revision: 42626

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 utils.ListOfMapsets()
(merge r42624 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2010-06-21 22:43:16 UTC (rev 42625)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gselect.py	2010-06-21 22:47:38 UTC (rev 42626)
@@ -233,7 +233,7 @@
         
         # list of mapsets in current location
         if mapsets is None:
-            mapsets = utils.ListOfMapsets()
+            mapsets = utils.ListOfMapsets(get = 'accessible')
         
         # map element types to g.mlist types
         elementdict = {'cell':'rast',

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2010-06-21 22:43:16 UTC (rev 42625)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/preferences.py	2010-06-21 22:47:38 UTC (rev 42626)
@@ -2185,8 +2185,8 @@
         
         wx.Dialog.__init__(self, parent, id, title, size = size, style = style, **kwargs)
 
-        self.all_mapsets_ordered = utils.ListOfMapsets(ordered=True)
-        self.accessible_mapsets = utils.ListOfMapsets(accessible=True)
+        self.all_mapsets_ordered = utils.ListOfMapsets(get = 'ordered')
+        self.accessible_mapsets  = utils.ListOfMapsets(get = 'accessible')
         self.curr_mapset = grass.gisenv()['MAPSET']
 
         # make a checklistbox from available mapsets and check those that are active

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2010-06-21 22:43:16 UTC (rev 42625)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/utils.py	2010-06-21 22:47:38 UTC (rev 42626)
@@ -209,77 +209,46 @@
         
     return catstr.strip(',')
 
-def ListOfMapsets(all=False, accessible=False, ordered=False):
+def ListOfMapsets(get = 'ordered'):
     """!Get list of available/accessible mapsets
 
-    @param all if True get list of all mapsets
-
+    @param get method ('all', 'accessible', 'ordered')
+    
     @return list of mapsets
+    @return None on error
     """
     mapsets = []
-
-    if all:
+    
+    if get == 'all' or get == 'ordered':
         ret = gcmd.RunCommand('g.mapsets',
                               read = True,
-                              fs = ';',
-                              flags = 'l')
+                              quiet = True,
+                              flags = 'l',
+                              fs = ';')
+        
         if ret:
             mapsets = ret.replace('\n', '').strip().split(';')
+            ListSortLower(mapsets)
         else:
-            raise gcmd.CmdError(cmd = 'g.mapsets',
-                                message = _('Unable to get list of available mapsets.'))
-
-    elif accessible:
+            return None
+        
+    if get == 'accessible' or get == 'ordered':
         ret = gcmd.RunCommand('g.mapsets',
                               read = True,
-                              fs = ';',
-                              flags = 'p')
+                              quiet = True,
+                              flags = 'p',
+                              fs = ';')
         if ret:
-            mapsets = ret.replace('\n', '').strip().split(';')
+            if get == 'accessible':
+                mapsets = ret.replace('\n', '').strip().split(';')
+            else:
+                mapsets_accessible = ret.replace('\n', '').strip().split(';')
+                for mapset in mapsets_accessible:
+                    mapsets.remove(mapset)
+                mapsets = mapsets_accessible + mapsets
         else:
-            raise gcmd.CmdError(cmd = 'g.mapsets',
-                                message = _('Unable to get list of accessible mapsets.'))
-
-    elif ordered:
-        ret = gcmd.RunCommand('g.mapsets',
-                              read = True,
-                              fs = ';',
-                              flags = 'l')
-        if ret:
-            mapsets_available = ret.replace('\n', '').strip().split(';')
-        else:
-            raise gcmd.CmdError(cmd = 'g.mapsets',
-                                message = _('Unable to get list of available mapsets.'))
- 
-        ret = gcmd.RunCommand('g.mapsets',
-                              read = True,
-                              fs = ';',
-                              flags = 'p')
-        if ret:
-            mapsets_accessible = ret.replace('\n', '').strip().split(';')
-        else:
-            raise gcmd.CmdError(cmd = 'g.mapsets',
-                                message = _('Unable to get list of accessible mapsets.'))
-
-        for mapset in mapsets_accessible:
-            mapsets_available.remove(mapset)
-        ListSortLower(mapsets_available)
-        mapsets = mapsets_accessible + mapsets_available
+            return None
     
-    else:
-        ret = gcmd.RunCommand('g.mapsets',
-                              read = True,
-                              fs = ';',
-                              flags = 'p')
-        if ret:
-            mapsets = ret.replace('\n', '').strip().split(';')
-        else:
-            raise gcmd.CmdError(cmd = 'g.mapsets',
-                                message = _('Unable to get list of accessible mapsets.'))
-        # This one sorts mapset names, thus prevents the user from modifying their
-        # order in the SEARH_PATH from GUI, unlike the `ordered' above.
-        ListSortLower(mapsets)
-    
     return mapsets
 
 def ListSortLower(list):



More information about the grass-commit mailing list