瀏覽代碼

wxGUI: clean up utils.ListOfMapsets()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42624 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 15 年之前
父節點
當前提交
69c2771227
共有 3 個文件被更改,包括 26 次插入57 次删除
  1. 1 1
      gui/wxpython/gui_modules/gselect.py
  2. 2 2
      gui/wxpython/gui_modules/preferences.py
  3. 23 54
      gui/wxpython/gui_modules/utils.py

+ 1 - 1
gui/wxpython/gui_modules/gselect.py

@@ -234,7 +234,7 @@ class TreeCtrlComboPopup(wx.combo.ComboPopup):
         
         # 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',

+ 2 - 2
gui/wxpython/gui_modules/preferences.py

@@ -2135,8 +2135,8 @@ class MapsetAccess(wx.Dialog):
         
         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

+ 23 - 54
gui/wxpython/gui_modules/utils.py

@@ -216,76 +216,45 @@ def ListOfCatsToRange(cats):
         
     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:
-        ret = gcmd.RunCommand('g.mapsets',
-                              read = True,
-                              flags = 'l',
-                              fs = ';')
-    
-        if ret:
-            mapsets = ret.rstrip('\n').split(';')
-        else:
-            raise gcmd.CmdError(cmd = 'g.mapsets',
-                                message = _('Unable to get list of available mapsets.'))
-
-    elif accessible:
-        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.'))
-
-    elif ordered:
+    if get == 'all' or get == 'ordered':
         ret = gcmd.RunCommand('g.mapsets',
                               read = True,
+                              quiet = 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 = ';')
+                              fs = 'newline')
+        
         if ret:
-            mapsets_accessible = ret.rstrip('\n').split(';')
+            mapsets = ret.splitlines()
+            ListSortLower(mapsets)
         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:
+            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.'))
-        # 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