[GRASS-SVN] r54902 - in grass/trunk/lib/python/pygrass: . raster vector
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Feb 4 07:26:47 PST 2013
Author: lucadelu
Date: 2013-02-04 07:26:47 -0800 (Mon, 04 Feb 2013)
New Revision: 54902
Modified:
grass/trunk/lib/python/pygrass/functions.py
grass/trunk/lib/python/pygrass/raster/abstract.py
grass/trunk/lib/python/pygrass/vector/abstract.py
Log:
add and fix doctest to functions.py, remove and unused function, fix abstract for vector and raster according the changes in functions.py
Modified: grass/trunk/lib/python/pygrass/functions.py
===================================================================
--- grass/trunk/lib/python/pygrass/functions.py 2013-02-04 15:26:32 UTC (rev 54901)
+++ grass/trunk/lib/python/pygrass/functions.py 2013-02-04 15:26:47 UTC (rev 54902)
@@ -45,39 +45,52 @@
def getenv(env):
- """Return the current grass environment variables:
+ """Return the current grass environment variables ::
>>> getenv("MAPSET")
'user1'
- .."""
+ """
return libgis.G__getenv(env)
def get_mapset_raster(mapname, mapset=''):
+ """Return the mapset of the raster map ::
+
+ >>> get_mapset_raster('elevation')
+ 'PERMANENT'
+
+ """
return libgis.G_find_raster(mapname, '')
def get_mapset_vector(mapname, mapset=''):
+ """Return the mapset of the vector map ::
+
+ >>> get_mapset_vector('census')
+ 'PERMANENT'
+
+ """
return libgis.G_find_vector(mapname, '')
-def exist(mapname, mapset=''):
- mapset = get_mapset_raster(mapname, mapset)
- if mapset != '':
- return True
- else:
- mapset = get_mapset_vector(mapname, mapset)
- if mapset:
- return True
- return False
+def is_clean_name(name):
+ """Return if the name is valid ::
+ >>> is_clean_name('census')
+ True
+ >>> is_clean_name('0census')
+ False
+ >>> is_clean_name('census&')
+ False
-def clean_map_name(name):
- name.strip()
+ """
+ if name[0].isdigit():
+ return False
for char in ' @#^?°,;%&/':
- name = name.replace(char, '')
- return name
+ if name.find(char) != -1:
+ return False
+ return True
def coor2pixel((east, north), region):
@@ -86,7 +99,7 @@
>>> reg = Region()
>>> coor2pixel((reg.west, reg.north), reg)
(0.0, 0.0)
- >>> coor2pixel((reg.east, reg.south), reg) == (reg.cols, reg.rows)
+ >>> coor2pixel((reg.east, reg.south), reg) == (reg.rows, reg.cols)
True
"""
return (libraster.Rast_northing_to_row(north, region.c_region),
@@ -99,7 +112,7 @@
>>> reg = Region()
>>> pixel2coor((0, 0), reg) == (reg.north, reg.west)
True
- >>> pixel2coor((reg.cols, reg.rows), reg) == (reg.east, reg.south)
+ >>> pixel2coor((reg.cols, reg.rows), reg) == (reg.south, reg.east)
True
"""
return (libraster.Rast_row_to_northing(row, region.c_region),
Modified: grass/trunk/lib/python/pygrass/raster/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/raster/abstract.py 2013-02-04 15:26:32 UTC (rev 54901)
+++ grass/trunk/lib/python/pygrass/raster/abstract.py 2013-02-04 15:26:47 UTC (rev 54902)
@@ -26,7 +26,7 @@
from grass.pygrass import functions
from grass.pygrass.gis.region import Region
from grass.pygrass.errors import must_be_open
-
+from grass.pygrass.gis import Mapset
#
# import raster classes
#
@@ -123,11 +123,12 @@
def _set_name(self, newname):
"""Private method to change the Raster name"""
- #import pdb; pdb.set_trace()
- cleanname = functions.clean_map_name(newname)
+ if not functions.is_clean_name(newname):
+ str_err = _("Map name {0} not valid")
+ raise ValueError(str_err.format(newname))
if self.exist():
- self.rename(cleanname)
- self._name = cleanname
+ self.rename(newname)
+ self._name = newname
name = property(fget=_get_name, fset=_set_name)
Modified: grass/trunk/lib/python/pygrass/vector/abstract.py
===================================================================
--- grass/trunk/lib/python/pygrass/vector/abstract.py 2013-02-04 15:26:32 UTC (rev 54901)
+++ grass/trunk/lib/python/pygrass/vector/abstract.py 2013-02-04 15:26:47 UTC (rev 54902)
@@ -90,7 +90,13 @@
return self._name
def _set_name(self, newname):
- self.rename(newname)
+ """Private method to change the Raster name"""
+ if not functions.is_clean_name(newname):
+ str_err = _("Map name {0} not valid")
+ raise ValueError(str_err.format(newname))
+ if self.exist():
+ self.rename(newname)
+ self._name = newname
name = property(fget=_get_name, fset=_set_name)
More information about the grass-commit
mailing list