Explorar el Código

Add some more check and options

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58116 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli hace 11 años
padre
commit
e4c5952b41
Se han modificado 1 ficheros con 8 adiciones y 9 borrados
  1. 8 9
      lib/python/pygrass/gis/__init__.py

+ 8 - 9
lib/python/pygrass/gis/__init__.py

@@ -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 @@ class Location(object):
             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 @@ class Location(object):
     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 @@ class Location(object):
             ['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