[GRASS-SVN] r44026 - grass/branches/releasebranch_6_4/lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 24 06:46:27 EDT 2010
Author: martinl
Date: 2010-10-24 03:46:27 -0700 (Sun, 24 Oct 2010)
New Revision: 44026
Modified:
grass/branches/releasebranch_6_4/lib/python/array.py
grass/branches/releasebranch_6_4/lib/python/core.py
grass/branches/releasebranch_6_4/lib/python/db.py
grass/branches/releasebranch_6_4/lib/python/raster.py
grass/branches/releasebranch_6_4/lib/python/vector.py
Log:
pythonlib: i18n / mapcalc() synced with devbr6
(merge r44023 from trunk)
Modified: grass/branches/releasebranch_6_4/lib/python/array.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/array.py 2010-10-24 10:43:12 UTC (rev 44025)
+++ grass/branches/releasebranch_6_4/lib/python/array.py 2010-10-24 10:46:27 UTC (rev 44026)
@@ -17,7 +17,6 @@
for details.
@author Glynn Clements
-
"""
import os
@@ -25,6 +24,10 @@
import core as grass
+# i18N
+import gettext
+gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+
class array(numpy.memmap):
def __new__(cls, dtype = numpy.double):
reg = grass.region()
@@ -58,10 +61,10 @@
elif kind in 'biu':
flags = 'i'
else:
- raise ValueError('invalid kind <%s>' % kind)
+ raise ValueError(_('invalid kind <%s>') % kind)
if size not in [1,2,4,8]:
- raise ValueError('invalid size <%d>' % size)
+ raise ValueError(_('invalid size <%d>') % size)
return grass.run_command(
'r.out.bin',
@@ -83,14 +86,14 @@
elif size == 8:
flags = 'd'
else:
- raise ValueError('invalid FP size <%d>' % size)
+ raise ValueError(_('invalid FP size <%d>') % size)
size = None
elif kind in 'biu':
if size not in [1,2,4]:
- raise ValueError('invalid integer size <%d>' % size)
+ raise ValueError(_('invalid integer size <%d>') % size)
flags = None
else:
- raise ValueError('invalid kind <%s>' % kind)
+ raise ValueError(_('invalid kind <%s>') % kind)
reg = grass.region()
Modified: grass/branches/releasebranch_6_4/lib/python/core.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/core.py 2010-10-24 10:43:12 UTC (rev 44025)
+++ grass/branches/releasebranch_6_4/lib/python/core.py 2010-10-24 10:46:27 UTC (rev 44026)
@@ -32,7 +32,7 @@
# i18N
import gettext
-gettext.install('grassmods', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
# subprocess wrapper that uses shell on Windows
Modified: grass/branches/releasebranch_6_4/lib/python/db.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/db.py 2010-10-24 10:43:12 UTC (rev 44025)
+++ grass/branches/releasebranch_6_4/lib/python/db.py 2010-10-24 10:46:27 UTC (rev 44026)
@@ -25,6 +25,10 @@
from core import *
+# i18N
+import gettext
+gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+
def db_describe(table, **args):
"""!Return the list of columns for a database table
(interface to `db.describe -c'). Example:
Modified: grass/branches/releasebranch_6_4/lib/python/raster.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/raster.py 2010-10-24 10:43:12 UTC (rev 44025)
+++ grass/branches/releasebranch_6_4/lib/python/raster.py 2010-10-24 10:46:27 UTC (rev 44026)
@@ -9,7 +9,6 @@
@code
from grass.script import raster as grass
-grass.parser()
grass.raster_history(map)
...
@endcode
@@ -28,6 +27,10 @@
from core import *
+# i18N
+import gettext
+gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+
# add raster history
def raster_history(map):
@@ -44,7 +47,8 @@
run_command('r.support', map = map, history = os.environ['CMDLINE'])
return True
- warning("Unable to write history for <%s>. Raster map <%s> not found in current mapset." % (map, map))
+ warning(_("Unable to write history for <%(map)s>. "
+ "Raster map <%(map)s> not found in current mapset." % { 'map' : map, 'map' : map}))
return False
# run "r.info -rgstmpud ..." and parse output
@@ -76,7 +80,7 @@
# interface to r.mapcalc
-def mapcalc(exp, **kwargs):
+def mapcalc(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
"""!Interface to r.mapcalc.
@param exp expression
@@ -84,17 +88,14 @@
"""
t = string.Template(exp)
e = t.substitute(**kwargs)
- verbose = os.getenv('GRASS_VERBOSE')
- if kwargs.has_key('quiet') and kwargs['quiet']:
- os.environ['GRASS_VERBOSE'] = '0'
- if kwargs.has_key('verbose') and kwargs['verbose']:
- os.environ['GRASS_VERBOSE'] = '3'
-
- if write_command('r.mapcalc', stdin = e) != 0:
- fatal("An error occurred while running r.mapcalc")
-
+
+ env = os.environ.copy()
+ if quiet:
+ env['GRASS_VERBOSE'] = '0'
if verbose:
- os.environ['GRASS_VERBOSE'] = verbose
- elif os.getenv('GRASS_VERBOSE'):
- del os.environ['GRASS_VERBOSE']
-
+ env['GRASS_VERBOSE'] = '3'
+ if overwrite:
+ env['GRASS_OVERWRITE'] = '1'
+
+ if write_command('r.mapcalc', stdin = e, env = env) != 0:
+ fatal(_("An error occurred while running r.mapcalc"))
Modified: grass/branches/releasebranch_6_4/lib/python/vector.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/vector.py 2010-10-24 10:43:12 UTC (rev 44025)
+++ grass/branches/releasebranch_6_4/lib/python/vector.py 2010-10-24 10:46:27 UTC (rev 44026)
@@ -27,6 +27,10 @@
from core import *
+# i18N
+import gettext
+gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'), unicode=True)
+
# run "v.db.connect -g ..." and parse output
def vector_db(map, **args):
@@ -83,7 +87,7 @@
try:
f = vector_db(map)[int(layer)]
except KeyError:
- fatal("Database connection not defined for layer %s" % layer)
+ fatal(_("Database connection not defined for layer %s") % layer)
return f
@@ -180,7 +184,8 @@
try:
key = vector_db(map = map)[layer]['key']
except KeyError:
- error('Missing layer %d in vector map <%s>' % (layer, map))
+ error(_('Missing layer %(layer)d in vector map <%(map)s>') % \
+ { 'layer' : layer, 'map' : map })
return { 'columns' : [], 'values' : {} }
if kwargs.has_key('columns'):
@@ -195,7 +200,7 @@
fs = '|', **kwargs)
if not ret:
- error('vector_select() failed')
+ error(_('vector_select() failed'))
return { 'columns' : [], 'values' : {} }
columns = []
More information about the grass-commit
mailing list