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

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 21 18:39:52 EDT 2010


Author: martinl
Date: 2010-06-21 22:39:52 +0000 (Mon, 21 Jun 2010)
New Revision: 42624

Modified:
   grass/trunk/gui/wxpython/gui_modules/gselect.py
   grass/trunk/gui/wxpython/gui_modules/preferences.py
   grass/trunk/gui/wxpython/gui_modules/utils.py
Log:
wxGUI: clean up utils.ListOfMapsets()


Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py	2010-06-21 22:19:22 UTC (rev 42623)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py	2010-06-21 22:39:52 UTC (rev 42624)
@@ -234,7 +234,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/trunk/gui/wxpython/gui_modules/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-06-21 22:19:22 UTC (rev 42623)
+++ grass/trunk/gui/wxpython/gui_modules/preferences.py	2010-06-21 22:39:52 UTC (rev 42624)
@@ -2135,8 +2135,8 @@
         
         wx.Dialog.__init__(self, parent, id, title, pos, size, style)
 
-        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/trunk/gui/wxpython/gui_modules/utils.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/utils.py	2010-06-21 22:19:22 UTC (rev 42623)
+++ grass/trunk/gui/wxpython/gui_modules/utils.py	2010-06-21 22:39:52 UTC (rev 42624)
@@ -216,76 +216,45 @@
         
     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,
+                              quiet = True,
                               flags = 'l',
-                              fs = ';')
-    
+                              fs = 'newline')
+        
         if ret:
-            mapsets = ret.rstrip('\n').split(';')
+            mapsets = ret.splitlines()
+            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,
+                              quiet = True,
                               flags = 'p',
-                              fs = ';')
+                              fs = 'newline')
         if ret:
-            mapsets = ret.rstrip('\n').split(';')
+            if get == 'accessible':
+                mapsets = ret.splitlines()
+            else:
+                mapsets_accessible = ret.splitlines()
+                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,
-                              flags = 'l',
-                              fs = ';')
-        if ret:
-            mapsets_available = ret.rstrip('\n').split(';')
-        else:
-            raise gcmd.CmdError(cmd = 'g.mapsets',
-                                message = _('Unable to get list of available mapsets.'))
- 
-        ret = gcmd.RunCommand('g.mapsets',
-                              read = True,
-                              flags = 'p',
-                              fs = ';')
-        if ret:
-            mapsets_accessible = ret.rstrip('\n').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)
-        mapsets = mapsets_accessible + mapsets_available
-
-    else:
-        ret = gcmd.RunCommand('g.mapsets',
-                              read = True,
-                              flags = 'p',
-                              fs = ';')
-        if ret:
-            mapsets = ret.rstrip('\n').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 None
     
     return mapsets
 



More information about the grass-commit mailing list