|
@@ -12,6 +12,7 @@ import fnmatch
|
|
|
|
|
|
import grass.lib.gis as libgis
|
|
|
from grass.pygrass.errors import GrassError
|
|
|
+from grass.script.utils import encode, decode
|
|
|
|
|
|
libgis.G_gisinit('')
|
|
|
|
|
@@ -46,7 +47,7 @@ def is_valid(value, path, type):
|
|
|
:return: True if valid else False
|
|
|
:rtype: str
|
|
|
"""
|
|
|
- return bool(CHECK_IS[type](join(path, value)))
|
|
|
+ return bool(CHECK_IS[type](encode(join(path, value))))
|
|
|
|
|
|
|
|
|
def _check_raise(value, path, type):
|
|
@@ -175,7 +176,7 @@ class Gisdbase(object):
|
|
|
..
|
|
|
"""
|
|
|
return sorted([loc for loc in listdir(self.name)
|
|
|
- if libgis.G_is_location(join(self.name, loc))])
|
|
|
+ if libgis.G_is_location(encode(join(self.name, loc)))])
|
|
|
|
|
|
|
|
|
class Location(object):
|
|
@@ -254,7 +255,7 @@ class Location(object):
|
|
|
mapsets = [mapset for mapset in self]
|
|
|
if permissions:
|
|
|
mapsets = [mapset for mapset in mapsets
|
|
|
- if libgis.G_mapset_permissions(mapset)]
|
|
|
+ if libgis.G_mapset_permissions(encode(mapset))]
|
|
|
if pattern:
|
|
|
return fnmatch.filter(mapsets, pattern)
|
|
|
return mapsets
|
|
@@ -402,11 +403,11 @@ class VisibleMapset(object):
|
|
|
|
|
|
def read(self):
|
|
|
"""Return the mapsets in the search path"""
|
|
|
- with open(self.spath, "a+") as f:
|
|
|
+ with open(self.spath, "ab+") as f:
|
|
|
lines = f.readlines()
|
|
|
if lines:
|
|
|
- return [l.strip() for l in lines]
|
|
|
- lns = ['PERMANENT', ]
|
|
|
+ return [decode(l.strip()) for l in lines]
|
|
|
+ lns = [u'PERMANENT', ]
|
|
|
self._write(lns)
|
|
|
return lns
|
|
|
|
|
@@ -416,9 +417,9 @@ class VisibleMapset(object):
|
|
|
:param mapsets: a list of mapset's names
|
|
|
:type mapsets: list
|
|
|
"""
|
|
|
- with open(self.spath, "w+") as f:
|
|
|
- ms = self.location.mapsets()
|
|
|
- f.write('%s' % '\n'.join([m for m in mapsets if m in ms]))
|
|
|
+ with open(self.spath, "wb+") as f:
|
|
|
+ ms = [decode(m) for m in self.location.mapsets()]
|
|
|
+ f.write(b'\n'.join([encode(m) for m in mapsets if m in ms]))
|
|
|
|
|
|
def add(self, mapset):
|
|
|
"""Add a mapset to the search path
|
|
@@ -448,8 +449,9 @@ class VisibleMapset(object):
|
|
|
:param mapsets: a list of mapset's names
|
|
|
:type mapsets: list
|
|
|
"""
|
|
|
- ms = self.location.mapsets()
|
|
|
- final = self.read()
|
|
|
+ ms = [decode(m) for m in self.location.mapsets()]
|
|
|
+ final = [decode(m) for m in self.read()]
|
|
|
+ mapsets = [decode(m) for m in mapsets]
|
|
|
final.extend([m for m in mapsets if m in ms and m not in final])
|
|
|
self._write(final)
|
|
|
|