[GRASS-SVN] r58116 - grass/trunk/lib/python/pygrass/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 28 07:10:01 PDT 2013


Author: zarch
Date: 2013-10-28 07:10:01 -0700 (Mon, 28 Oct 2013)
New Revision: 58116

Modified:
   grass/trunk/lib/python/pygrass/gis/__init__.py
Log:
Add some more check and options

Modified: grass/trunk/lib/python/pygrass/gis/__init__.py
===================================================================
--- grass/trunk/lib/python/pygrass/gis/__init__.py	2013-10-28 14:08:02 UTC (rev 58115)
+++ grass/trunk/lib/python/pygrass/gis/__init__.py	2013-10-28 14:10:01 UTC (rev 58116)
@@ -1,9 +1,8 @@
 # -*- coding: utf-8 -*-
 #!/usr/bin/env python2.7
 from __future__ import print_function
-#import os
 from os import listdir
-from os.path import join
+from os.path import join, exists, isdir
 import shutil
 import ctypes as ct
 import fnmatch
@@ -182,12 +181,9 @@
             raise KeyError('Mapset: %s does not exist' % mapset)
 
     def __iter__(self):
-        for mapset in libgis.G_available_mapsets():
-            mapset_name = ct.cast(mapset, ct.c_char_p).value
-            if mapset_name and libgis.G__mapset_permissions(mapset):
-                yield mapset_name
-            else:
-                break
+        lpath = self.path()
+        return (m for m in listdir(lpath)
+                if (isdir(join(lpath, m)) and _check(m, lpath, "MAPSET")))
 
     def __len__(self):
         return len(self.mapsets())
@@ -198,7 +194,7 @@
     def __repr__(self):
         return 'Location(%r)' % self.name
 
-    def mapsets(self, pattern=None):
+    def mapsets(self, pattern=None, permissions=True):
         """Return a list of the available mapsets. ::
 
             >>> location = Location()
@@ -206,6 +202,9 @@
             ['PERMANENT', 'user1']
         """
         mapsets = [mapset for mapset in self]
+        if permissions:
+            mapsets = [mapset for mapset in mapsets
+                       if libgis.G__mapset_permissions(mapset)]
         if pattern:
             return fnmatch.filter(mapsets, pattern)
         return mapsets



More information about the grass-commit mailing list