[GRASS-SVN] r62786 - in grass/branches/releasebranch_7_0: . gui/wxpython/vdigit lib/python/script lib/python/temporal scripts/d.shadedmap scripts/db.dropcolumn scripts/db.in.ogr scripts/db.out.ogr scripts/db.test scripts/g.extension.all scripts/i.in.spotvgt scripts/r.fillnulls scripts/r.grow scripts/r.in.srtm scripts/r.in.wms scripts/r.mask scripts/r.out.xyz scripts/r3.in.xyz scripts/v.build.all scripts/v.convert.all scripts/v.db.addtable scripts/v.db.dropcolumn scripts/v.db.droprow scripts/v.db.droptable scripts/v.db.join scripts/v.db.reconnect.all scripts/v.dissolve scripts/v.in.e00 scripts/v.in.gps scripts/v.in.mapgen scripts/v.in.wfs scripts/v.out.gps scripts/v.rast.stats scripts/v.to.lines scripts/v.unpack scripts/v.what.vect temporal/t.rast.colors temporal/t.rast.out.vtk temporal/t.rast.series temporal/t.rast.to.rast3 temporal/t.vect.observe.strds temporal/t.vect.what.strds

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Nov 17 18:33:39 PST 2014


Author: wenzeslaus
Date: 2014-11-17 18:33:39 -0800 (Mon, 17 Nov 2014)
New Revision: 62786

Modified:
   grass/branches/releasebranch_7_0/
   grass/branches/releasebranch_7_0/gui/wxpython/vdigit/g.gui.vdigit.py
   grass/branches/releasebranch_7_0/lib/python/script/array.py
   grass/branches/releasebranch_7_0/lib/python/script/core.py
   grass/branches/releasebranch_7_0/lib/python/script/db.py
   grass/branches/releasebranch_7_0/lib/python/script/raster.py
   grass/branches/releasebranch_7_0/lib/python/script/raster3d.py
   grass/branches/releasebranch_7_0/lib/python/temporal/aggregation.py
   grass/branches/releasebranch_7_0/lib/python/temporal/extract.py
   grass/branches/releasebranch_7_0/lib/python/temporal/mapcalc.py
   grass/branches/releasebranch_7_0/lib/python/temporal/stds_export.py
   grass/branches/releasebranch_7_0/lib/python/temporal/stds_import.py
   grass/branches/releasebranch_7_0/scripts/d.shadedmap/d.shadedmap.py
   grass/branches/releasebranch_7_0/scripts/db.dropcolumn/db.dropcolumn.py
   grass/branches/releasebranch_7_0/scripts/db.in.ogr/db.in.ogr.py
   grass/branches/releasebranch_7_0/scripts/db.out.ogr/db.out.ogr.py
   grass/branches/releasebranch_7_0/scripts/db.test/db.test.py
   grass/branches/releasebranch_7_0/scripts/g.extension.all/g.extension.all.py
   grass/branches/releasebranch_7_0/scripts/i.in.spotvgt/i.in.spotvgt.py
   grass/branches/releasebranch_7_0/scripts/r.fillnulls/r.fillnulls.py
   grass/branches/releasebranch_7_0/scripts/r.grow/r.grow.py
   grass/branches/releasebranch_7_0/scripts/r.in.srtm/r.in.srtm.py
   grass/branches/releasebranch_7_0/scripts/r.in.wms/wms_base.py
   grass/branches/releasebranch_7_0/scripts/r.mask/r.mask.py
   grass/branches/releasebranch_7_0/scripts/r.out.xyz/r.out.xyz.py
   grass/branches/releasebranch_7_0/scripts/r3.in.xyz/r3.in.xyz.py
   grass/branches/releasebranch_7_0/scripts/v.build.all/v.build.all.py
   grass/branches/releasebranch_7_0/scripts/v.convert.all/v.convert.all.py
   grass/branches/releasebranch_7_0/scripts/v.db.addtable/v.db.addtable.py
   grass/branches/releasebranch_7_0/scripts/v.db.dropcolumn/v.db.dropcolumn.py
   grass/branches/releasebranch_7_0/scripts/v.db.droprow/v.db.droprow.py
   grass/branches/releasebranch_7_0/scripts/v.db.droptable/v.db.droptable.py
   grass/branches/releasebranch_7_0/scripts/v.db.join/v.db.join.py
   grass/branches/releasebranch_7_0/scripts/v.db.reconnect.all/v.db.reconnect.all.py
   grass/branches/releasebranch_7_0/scripts/v.dissolve/v.dissolve.py
   grass/branches/releasebranch_7_0/scripts/v.in.e00/v.in.e00.py
   grass/branches/releasebranch_7_0/scripts/v.in.gps/v.in.gps.py
   grass/branches/releasebranch_7_0/scripts/v.in.mapgen/v.in.mapgen.py
   grass/branches/releasebranch_7_0/scripts/v.in.wfs/v.in.wfs.py
   grass/branches/releasebranch_7_0/scripts/v.out.gps/v.out.gps.py
   grass/branches/releasebranch_7_0/scripts/v.rast.stats/v.rast.stats.py
   grass/branches/releasebranch_7_0/scripts/v.to.lines/v.to.lines.py
   grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py
   grass/branches/releasebranch_7_0/scripts/v.what.vect/v.what.vect.py
   grass/branches/releasebranch_7_0/temporal/t.rast.colors/t.rast.colors.py
   grass/branches/releasebranch_7_0/temporal/t.rast.out.vtk/t.rast.out.vtk.py
   grass/branches/releasebranch_7_0/temporal/t.rast.series/t.rast.series.py
   grass/branches/releasebranch_7_0/temporal/t.rast.to.rast3/t.rast.to.rast3.py
   grass/branches/releasebranch_7_0/temporal/t.vect.observe.strds/t.vect.observe.strds.py
   grass/branches/releasebranch_7_0/temporal/t.vect.what.strds/t.vect.what.strds.py
Log:
pythonlib: raise exceptions from run_command and others (#2326, backport r62566)


Property changes on: grass/branches/releasebranch_7_0
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk:60817,61096,61141,62179-62180,62182,62403,62422,62424,62437,62466,62469,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62570,62573,62575,62585,62588,62597,62603,62606,62608-62609,62614,62618,62628,62632,62638,62642,62648-62649,62652,62654-62657,62666,62723,62730,62739,62741,62743,62746,62750,62752,62757,62762
   + /grass/trunk:60817,61096,61141,62179-62180,62182,62403,62422,62424,62437,62466,62469,62487,62491,62494,62501,62506,62508-62509,62515,62518-62519,62521,62526,62533,62539,62541,62555,62562,62566,62570,62573,62575,62585,62588,62597,62603,62606,62608-62609,62614,62618,62628,62632,62638,62642,62648-62649,62652,62654-62657,62666,62723,62730,62739,62741,62743,62746,62750,62752,62757,62762

Modified: grass/branches/releasebranch_7_0/gui/wxpython/vdigit/g.gui.vdigit.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/vdigit/g.gui.vdigit.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/gui/wxpython/vdigit/g.gui.vdigit.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -46,7 +46,9 @@
 from core.giface import StandaloneGrassInterface
 from core.settings import UserSettings
 from vdigit.main import haveVDigit, errorMsg
+from grass.exceptions import CalledModuleError
 
+
 class VDigitMapFrame(MapFrame):
     def __init__(self, vectorMap):
         MapFrame.__init__(self, parent = None, giface = StandaloneGrassInterface(),
@@ -95,7 +97,9 @@
                           "New vector map can be created by providing '-c' flag.") % options['map'])
         else:
             grass.message(_("New vector map <%s> created") % options['map'])
-            if 0 != grass.run_command('v.edit', map = options['map'], tool = 'create'):
+            try:
+                grass.run_command('v.edit', map = options['map'], tool = 'create')
+            except CalledModuleError:
                 grass.fatal(_("Unable to create new vector map <%s>") % options['map'])
     
     GuiModuleMain(main)

Modified: grass/branches/releasebranch_7_0/lib/python/script/array.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/array.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/script/array.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -121,6 +121,7 @@
 
 from utils import try_remove
 import core as grass
+from grass.exceptions import CalledModuleError
 
 
 ###############################################################################
@@ -176,15 +177,20 @@
         if size not in [1, 2, 4, 8]:
             raise ValueError(_('Invalid size <%d>') % size)
 
-        return grass.run_command(
-            'r.out.bin',
-            flags=flags,
-            input=mapname,
-            output=self.filename,
-            bytes=size,
-            null=null,
-            quiet=True,
-            overwrite=True)
+        try:
+            grass.run_command(
+                'r.out.bin',
+                flags=flags,
+                input=mapname,
+                output=self.filename,
+                bytes=size,
+                null=null,
+                quiet=True,
+                overwrite=True)
+        except CalledModuleError:
+            return 1
+        else:
+            return 0
 
     def write(self, mapname, title=None, null=None, overwrite=None):
         """Write array into raster map
@@ -217,21 +223,26 @@
 
         reg = grass.region()
 
-        return grass.run_command(
-            'r.in.bin',
-            flags=flags,
-            input=self.filename,
-            output=mapname,
-            title=title,
-            bytes=size,
-            anull=null,
-            overwrite=overwrite,
-            north=reg['n'],
-            south=reg['s'],
-            east=reg['e'],
-            west=reg['w'],
-            rows=reg['rows'],
-            cols=reg['cols'])
+        try:
+            grass.run_command(
+                'r.in.bin',
+                flags=flags,
+                input=self.filename,
+                output=mapname,
+                title=title,
+                bytes=size,
+                anull=null,
+                overwrite=overwrite,
+                north=reg['n'],
+                south=reg['s'],
+                east=reg['e'],
+                west=reg['w'],
+                rows=reg['rows'],
+                cols=reg['cols'])
+        except CalledModuleError:
+            return 1
+        else:
+            return 0
 
 ###############################################################################
 
@@ -290,15 +301,20 @@
         if size not in [1, 2, 4, 8]:
             raise ValueError(_('Invalid size <%d>') % size)
 
-        return grass.run_command(
-            'r3.out.bin',
-            flags=flags,
-            input=mapname,
-            output=self.filename,
-            bytes=size,
-            null=null,
-            quiet=True,
-            overwrite=True)
+        try:
+            grass.run_command(
+                'r3.out.bin',
+                flags=flags,
+                input=mapname,
+                output=self.filename,
+                bytes=size,
+                null=null,
+                quiet=True,
+                overwrite=True)
+        except CalledModuleError:
+            exit(1)
+        else:
+            exit(0)
 
     def write(self, mapname, null=None, overwrite=None):
         """Write array into 3D raster map
@@ -326,20 +342,26 @@
 
         reg = grass.region(True)
 
-        return grass.run_command(
-            'r3.in.bin',
-            flags=flags,
-            input=self.filename,
-            output=mapname,
-            bytes=size,
-            null=null,
-            overwrite=overwrite,
-            north=reg['n'],
-            south=reg['s'],
-            top=reg['t'],
-            bottom=reg['b'],
-            east=reg['e'],
-            west=reg['w'],
-            depths=reg['depths'],
-            rows=reg['rows3'],
-            cols=reg['cols3'])
+        try:
+            grass.run_command(
+                'r3.in.bin',
+                flags=flags,
+                input=self.filename,
+                output=mapname,
+                bytes=size,
+                null=null,
+                overwrite=overwrite,
+                north=reg['n'],
+                south=reg['s'],
+                top=reg['t'],
+                bottom=reg['b'],
+                east=reg['e'],
+                west=reg['w'],
+                depths=reg['depths'],
+                rows=reg['rows3'],
+                cols=reg['cols3'])
+
+        except CalledModuleError:
+            exit(1)
+        else:
+            exit(0)

Modified: grass/branches/releasebranch_7_0/lib/python/script/core.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/core.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/script/core.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -29,9 +29,8 @@
 import types as python_types
 
 from utils import KeyValue, parse_key_val, basename, encode
+from grass.exceptions import ScriptError, CalledModuleError
 
-from grass.exceptions import ScriptError
-
 # i18N
 import gettext
 gettext.install('grasslibs', os.path.join(os.getenv("GISBASE"), 'locale'))
@@ -354,7 +353,15 @@
     :return: exit code (0 for success)
     """
     ps = start_command(*args, **kwargs)
-    return ps.wait()
+    returncode = ps.wait()
+    if returncode:
+        # TODO: construction of the whole command is far from perfect
+        args = make_command(*args, **kwargs)
+        raise CalledModuleError(module=None, code=' '.join(args),
+                                returncode=returncode)
+    else:
+        # the else is just for compatibility, remove before 7.1
+        return 0
 
 
 def pipe_command(*args, **kwargs):
@@ -403,8 +410,15 @@
 
     :return: stdout
     """
-    ps = pipe_command(*args, **kwargs)
-    return ps.communicate()[0]
+    process = pipe_command(*args, **kwargs)
+    stdout, unused = process.communicate()
+    returncode = process.poll()
+    if returncode:
+        # TODO: construction of the whole command is far from perfect
+        args = make_command(*args, **kwargs)
+        raise CalledModuleError(module=None, code=' '.join(args),
+                                returncode=returncode)
+    return stdout
 
 
 def parse_command(*args, **kwargs):
@@ -459,10 +473,17 @@
     :return: return code
     """
     stdin = kwargs['stdin']
-    p = feed_command(*args, **kwargs)
-    p.stdin.write(stdin)
-    p.stdin.close()
-    return p.wait()
+    process = feed_command(*args, **kwargs)
+    process.communicate(stdin)
+    returncode = process.poll()
+    if returncode:
+        # TODO: construction of the whole command is far from perfect
+        args = make_command(*args, **kwargs)
+        raise CalledModuleError(module=None, code=' '.join(args),
+                                returncode=returncode)
+    else:
+        # the else is just for compatibility, remove before 7.1
+        return 0
 
 
 def exec_command(prog, flags="", overwrite=False, quiet=False, verbose=False,

Modified: grass/branches/releasebranch_7_0/lib/python/script/db.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/db.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/script/db.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -21,6 +21,7 @@
 
 from core import *
 from utils import try_remove
+from grass.exceptions import CalledModuleError
 
 
 def db_describe(table, **args):
@@ -80,13 +81,16 @@
     :return: True for success, False otherwise
     """
     nuldev = file(os.devnull, 'w+')
-    ret = run_command('db.describe', flags = 'c', table = table,
-                      stdout = nuldev, stderr = nuldev, **args)
-    nuldev.close()
+    ok = True
+    try:
+        run_command('db.describe', flags='c', table=table,
+                    stdout=nuldev, stderr=nuldev, **args)
+    except CalledModuleError:
+        ok = False
+    finally:
+        nuldev.close()
     
-    if ret == 0:
-        return True
-    return False
+    return ok
 
 def db_connection(force=False):
     """Return the current database connection parameters
@@ -146,13 +150,11 @@
 
     if 'sep' not in args:
         args['sep'] = '|'
-    
-    ret = run_command('db.select', quiet = True,
-                      flags = 'c',
-                      output = fname,
-                      **args)
-    
-    if ret != 0:
+
+    try:
+        run_command('db.select', quiet=True, flags='c',
+                    output=fname, **args)
+    except CalledModuleError:
         fatal(_("Fetching data failed"))
 
     ofile = open(fname)

Modified: grass/branches/releasebranch_7_0/lib/python/script/raster.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/raster.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/script/raster.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -24,6 +24,7 @@
 import time
 
 from core import *
+from grass.exceptions import CalledModuleError
 from utils import float_or_dms, parse_key_val
 
 
@@ -97,12 +98,10 @@
     t = string.Template(exp)
     e = t.substitute(**kwargs)
 
-    if write_command('r.mapcalc', file = '-', stdin = e,
-                     env = env,
-                     seed = seed,
-                     quiet = quiet,
-                     verbose = verbose,
-                     overwrite = overwrite) != 0:
+    try:
+        write_command('r.mapcalc', file='-', stdin=e, env=env, seed=seed,
+                      quiet=quiet, verbose=verbose, overwrite=overwrite)
+    except CalledModuleError:
         fatal(_("An error occurred while running r.mapcalc"))
 
 

Modified: grass/branches/releasebranch_7_0/lib/python/script/raster3d.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/raster3d.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/script/raster3d.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -23,6 +23,7 @@
 
 from core import *
 from utils import float_or_dms, parse_key_val
+from grass.exceptions import CalledModuleError
 
 
 def raster3d_info(map):
@@ -75,8 +76,10 @@
     t = string.Template(exp)
     e = t.substitute(**kwargs)
 
-    if run_command('r3.mapcalc', expression = e,
-                   quiet = quiet,
-                   verbose = verbose,
-                   overwrite = overwrite) != 0:
+    try:
+        run_command('r3.mapcalc', expression=e,
+                    quiet=quiet,
+                    verbose=verbose,
+                    overwrite=overwrite)
+    except CalledModuleError:
         fatal(_("An error occurred while running r3.mapcalc"))

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/aggregation.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/aggregation.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/aggregation.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -24,6 +24,7 @@
 """
 
 from space_time_datasets import *
+from grass.exceptions import CalledModuleError
 
 ###############################################################################
 
@@ -154,16 +155,17 @@
     file.close()
     
     # Run r.series
-    if len(inputs) > 1000 :
-        ret = core.run_command("r.series", flags="z", file=filename,
-                               output=output, overwrite=core.overwrite(),
-                               method=method)
-    else:
-        ret = core.run_command("r.series", file=filename,
-                               output=output, overwrite=core.overwrite(),
-                               method=method)
+    try:
+        if len(inputs) > 1000:
+            gscript.run_command("r.series", flags="z", file=filename,
+                                output=output, overwrite=gscript.overwrite(),
+                                method=method)
+        else:
+            gscript.run_command("r.series", file=filename,
+                                output=output, overwrite=gscript.overwrite(),
+                                method=method)
 
-    if ret != 0:
+    except CalledModuleError:
         dbif.close()
         msgr.fatal(_("Error occurred in r.series computation"))
 

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/extract.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/extract.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/extract.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -17,6 +17,7 @@
 from open_stds import *
 from multiprocessing import Process
 import grass.script as gscript
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -250,18 +251,27 @@
 
 def run_mapcalc2d(expr):
     """Helper function to run r.mapcalc in parallel"""
-    exit(gscript.run_command("r.mapcalc", expression=expr,
-                            overwrite=gscript.overwrite(), quiet=True))
+    try:
+        gscript.run_command("r.mapcalc", expression=expr,
+                            overwrite=gscript.overwrite(), quiet=True)
+    except CalledModuleError:
+        exit(1)
 
 
 def run_mapcalc3d(expr):
     """Helper function to run r3.mapcalc in parallel"""
-    exit(gscript.run_command("r3.mapcalc", expression=expr,
-                            overwrite=gscript.overwrite(), quiet=True))
+    try:
+        gscript.run_command("r3.mapcalc", expression=expr,
+                            overwrite=gscript.overwrite(), quiet=True)
+    except CalledModuleError:
+        exit(1)
 
 
 def run_vector_extraction(input, output, layer, type, where):
     """Helper function to run r.mapcalc in parallel"""
-    exit(gscript.run_command("v.extract", input=input, output=output,
+    try:
+        gscript.run_command("v.extract", input=input, output=output,
                             layer=layer, type=type, where=where,
-                            overwrite=gscript.overwrite(), quiet=True))
+                            overwrite=gscript.overwrite(), quiet=True)
+    except CalledModuleError:
+        exit(1)

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/mapcalc.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/mapcalc.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/mapcalc.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -16,6 +16,7 @@
 from open_stds import *
 from multiprocessing import Process
 import grass.script as gscript
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -342,16 +343,22 @@
 
 def _run_mapcalc2d(expr):
     """Helper function to run r.mapcalc in parallel"""
-    exit(gscript.run_command("r.mapcalc", expression=expr,
-                            overwrite=gscript.overwrite(), quiet=True))
+    try:
+        gscript.run_command("r.mapcalc", expression=expr,
+                            overwrite=gscript.overwrite(), quiet=True)
+    except CalledModuleError:
+        exit(1)
 
 ###############################################################################
 
 
 def _run_mapcalc3d(expr):
     """Helper function to run r3.mapcalc in parallel"""
-    exit(gscript.run_command("r3.mapcalc", expression=expr,
-                            overwrite=gscript.overwrite(), quiet=True))
+    try:
+        gscript.run_command("r3.mapcalc", expression=expr,
+                            overwrite=gscript.overwrite(), quiet=True)
+    except CalledModuleError:
+        exit(1)
 
 ###############################################################################
 

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/stds_export.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/stds_export.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/stds_export.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -36,7 +36,9 @@
 from space_time_datasets import *
 from factory import *
 from open_stds import *
+from grass.exceptions import CalledModuleError
 
+
 proj_file_name = "proj.txt"
 init_file_name = "init.txt"
 metadata_file_name = "metadata.txt"
@@ -66,31 +68,34 @@
         # Write the filename, the start_time and the end_time
         list_file.write(string)
 
-        if format_ == "GTiff":
-            # Export the raster map with r.out.gdal as tif
-            out_name = name + ".tif"
-            if datatype == "CELL":
-                nodata = max_val + 1
-                if nodata < 256 and min_val >= 0:
-                    gdal_type = "Byte"
-                elif nodata < 65536 and min_val >= 0:
-                    gdal_type = "UInt16"
-                elif min_val >= 0:
-                    gdal_type = "UInt32"
+        try:
+            if format_ == "GTiff":
+                # Export the raster map with r.out.gdal as tif
+                out_name = name + ".tif"
+                if datatype == "CELL":
+                    nodata = max_val + 1
+                    if nodata < 256 and min_val >= 0:
+                        gdal_type = "Byte"
+                    elif nodata < 65536 and min_val >= 0:
+                        gdal_type = "UInt16"
+                    elif min_val >= 0:
+                        gdal_type = "UInt32"
+                    else:
+                        gdal_type = "Int32"
+                    gscript.run_command("r.out.gdal", flags="c", input=name,
+                                        output=out_name, nodata=nodata,
+                                        type=gdal_type, format="GTiff")
                 else:
-                    gdal_type = "Int32"
-                ret = core.run_command("r.out.gdal", flags="c", input=name,
-                                    output=out_name, nodata=nodata,
-                                    type=gdal_type, format="GTiff")
-            else:
-                ret = core.run_command("r.out.gdal", flags="c",
-                                    input=name, output=out_name, format="GTiff")
-        elif format_ == "AAIGrid":
-            # Export the raster map with r.out.gdal as Arc/Info ASCII Grid
-            out_name = name + ".asc"
-            ret = core.run_command("r.out.gdal", flags="c", input=name, output=out_name, format="AAIGrid")
-            
-        if ret != 0:
+                    gscript.run_command("r.out.gdal", flags="c",
+                                        input=name, output=out_name,
+                                        format="GTiff")
+            elif format_ == "AAIGrid":
+                # Export the raster map with r.out.gdal as Arc/Info ASCII Grid
+                out_name = name + ".asc"
+                gscript.run_command("r.out.gdal", flags="c", input=name,
+                                    output=out_name, format="AAIGrid")
+
+        except CalledModuleError:
             shutil.rmtree(new_cwd)
             tar.close()
             core.fatal(_("Unable to export raster map <%s>" % name))
@@ -99,8 +104,9 @@
 
         # Export the color rules
         out_name = name + ".color"
-        ret = core.run_command("r.colors.out", map=name, rules=out_name)
-        if ret != 0:
+        try:
+            gscript.run_command("r.colors.out", map=name, rules=out_name)
+        except CalledModuleError:
             shutil.rmtree(new_cwd)
             tar.close()
             core.fatal(_("Unable to export color rules for raster "
@@ -121,8 +127,9 @@
         # Write the filename, the start_time and the end_time
         list_file.write(string)
         # Export the raster map with r.pack
-        ret = core.run_command("r.pack", input=name, flags="c")
-        if ret != 0:
+        try:
+            gscript.run_command("r.pack", input=name, flags="c")
+        except CalledModuleError:
             shutil.rmtree(new_cwd)
             tar.close()
             core.fatal(_("Unable to export raster map <%s> with r.pack" %
@@ -146,9 +153,10 @@
         # Write the filename, the start_time and the end_time
         list_file.write(string)
         # Export the vector map with v.out.ogr
-        ret = core.run_command("v.out.ogr", input=name, dsn=(name + ".xml"),
-                               layer=layer, format="GML")
-        if ret != 0:
+        try:
+            gscript.run_command("v.out.ogr", input=name, dsn=(name + ".xml"),
+                                layer=layer, format="GML")
+        except CalledModuleError:
             shutil.rmtree(new_cwd)
             tar.close()
             core.fatal(_("Unable to export vector map <%s> as "
@@ -178,8 +186,9 @@
         # Write the filename, the start_time and the end_time
         list_file.write(string)
         # Export the vector map with v.pack
-        ret = core.run_command("v.pack", input=name, flags="c")
-        if ret != 0:
+        try:
+            gscript.run_command("v.pack", input=name, flags="c")
+        except CalledModuleError:
             shutil.rmtree(new_cwd)
             tar.close()
             core.fatal(_("Unable to export vector map <%s> with v.pack" %
@@ -203,8 +212,9 @@
         # Write the filename, the start_time and the end_time
         list_file.write(string)
         # Export the raster 3d map with r3.pack
-        ret = core.run_command("r3.pack", input=name, flags="c")
-        if ret != 0:
+        try:
+            gscript.run_command("r3.pack", input=name, flags="c")
+        except CalledModuleError:
             shutil.rmtree(new_cwd)
             tar.close()
             core.fatal(_("Unable to export raster map <%s> with r3.pack" %

Modified: grass/branches/releasebranch_7_0/lib/python/temporal/stds_import.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/temporal/stds_import.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/lib/python/temporal/stds_import.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -41,6 +41,7 @@
 import factory
 from factory import *
 import grass.script as gscript
+from grass.exceptions import CalledModuleError
 
 proj_file_name = "proj.txt"
 init_file_name = "init.txt"
@@ -70,28 +71,30 @@
             if not overr:
                 impflags += "o"
 
-        if link:
-            ret = gscript.run_command("r.external", input=filename,
-                                   output=name,
-                                   flags=impflags,
-                                   overwrite=gscript.overwrite())
-        else:
-            ret = gscript.run_command("r.in.gdal", input=filename,
-                                   output=name,
-                                   flags=impflags,
-                                   overwrite=gscript.overwrite())
+        try:
+            if link:
+                gscript.run_command("r.external", input=filename,
+                                    output=name,
+                                    flags=impflags,
+                                    overwrite=gscript.overwrite())
+            else:
+                gscript.run_command("r.in.gdal", input=filename,
+                                    output=name,
+                                    flags=impflags,
+                                    overwrite=gscript.overwrite())
 
-        if ret != 0:
+        except CalledModuleError:
             gscript.fatal(_("Unable to import/link raster map <%s> from file %s.") %(name, 
                                                                      filename))
 
         # Set the color rules if present
         filename = row["filename"] + ".color"
         if os.path.isfile(filename):
-            ret = gscript.run_command("r.colors", map=name,
-                                   rules=filename,
-                                   overwrite=gscript.overwrite())
-            if ret != 0:
+            try:
+                gscript.run_command("r.colors", map=name,
+                                    rules=filename,
+                                    overwrite=gscript.overwrite())
+            except CalledModuleError:
                 gscript.fatal(_("Unable to set the color rules for "
                              "raster map <%s>.") % name)
 
@@ -109,13 +112,13 @@
     for row in maplist:
         name = row["name"]
         filename = row["filename"] + ".pack"
-        ret = gscript.run_command("r.unpack", input=filename,
-                               output=name,
-                               flags=impflags,
-                               overwrite=gscript.overwrite(),
-                               verbose=True)
+        try:
+            gscript.run_command("r.unpack", input=filename,
+                                output=name, flags=impflags,
+                                overwrite=gscript.overwrite(),
+                                verbose=True)
 
-        if ret != 0:
+        except CalledModuleError:
             gscript.fatal(_("Unable to unpack raster map <%s> from file %s.") % (name, 
                                                                               filename))
 
@@ -134,12 +137,12 @@
         name = row["name"]
         filename = row["filename"] + ".xml"
 
-        ret = gscript.run_command("v.in.ogr", dsn=filename,
-                               output=name,
-                               flags=impflags,
-                               overwrite=gscript.overwrite())
+        try:
+            gscript.run_command("v.in.ogr", dsn=filename,
+                                output=name, flags=impflags,
+                                overwrite=gscript.overwrite())
 
-        if ret != 0:
+        except CalledModuleError:
             gscript.fatal(_("Unable to import vector map <%s> from file %s.") % (name,
                                                                               filename))
 
@@ -157,13 +160,13 @@
         if name in imported_maps:
             continue
         filename = row["filename"] + ".pack"
-        ret = gscript.run_command("v.unpack", input=filename,
-                               output=name,
-                               flags=impflags,
-                               overwrite=gscript.overwrite(),
-                               verbose=True)
+        try:
+            gscript.run_command("v.unpack", input=filename,
+                                output=name, flags=impflags,
+                                overwrite=gscript.overwrite(),
+                                verbose=True)
 
-        if ret != 0:
+        except CalledModuleError:
             gscript.fatal(_("Unable to unpack vector map <%s> from file %s.") % (name, 
                                                                               filename))
 
@@ -267,14 +270,16 @@
             gscript.fatal(_("Unable to create location %(l)s. Reason: %(e)s")
                          % {'l': location, 'e': str(e)})
         # Switch to the new created location
-        ret = gscript.run_command("g.mapset", mapset="PERMANENT",
-                               location=location,
-                               gisdbase=old_env["GISDBASE"])
-        if ret != 0:
+        try:
+            gscript.run_command("g.mapset", mapset="PERMANENT",
+                                location=location,
+                                gisdbase=old_env["GISDBASE"])
+        except CalledModuleError:
             gscript.fatal(_("Unable to switch to location %s") % location)
         # create default database connection
-        ret = gscript.run_command("t.connect", flags="d")
-        if ret != 0:
+        try:
+            gscript.run_command("t.connect", flags="d")
+        except CalledModuleError:
             gscript.fatal(_("Unable to create default temporal database "
                          "in new location %s") % location)
 
@@ -461,8 +466,11 @@
     finally:
         if location:
             # Switch to the old location
-            ret = gscript.run_command("g.mapset", mapset=old_env["MAPSET"],
-                                   location=old_env["LOCATION_NAME"],
-                                   gisdbase=old_env["GISDBASE"])
+            try:
+                gscript.run_command("g.mapset", mapset=old_env["MAPSET"],
+                                    location=old_env["LOCATION_NAME"],
+                                    gisdbase=old_env["GISDBASE"])
+            except CalledModuleError:
+                grass.warning(_("Switching to original location failed"))
 
         gscript.set_raise_on_error(old_state)

Modified: grass/branches/releasebranch_7_0/scripts/d.shadedmap/d.shadedmap.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/d.shadedmap/d.shadedmap.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/d.shadedmap/d.shadedmap.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -43,7 +43,9 @@
 import os
 import sys
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     drape_map = options['drapemap']
     relief_map = options['reliefmap']
@@ -63,10 +65,13 @@
         grass.run_command('g.remove', quiet=True, flags='f',
                           type='rast', name='%s,%s,%s' % (tmp_r, tmp_g, tmp_b))
 
+    ret = 0
+    try:
+        grass.run_command('d.his', h_map=drape_map, i_map=relief_map,
+                          brighten=brighten)
+    except CalledModuleError:
+        ret = 1
 
-    ret = grass.run_command("d.his", h_map = drape_map, i_map = relief_map,
-                            brighten = brighten)
-
     sys.exit(ret)
 
 

Modified: grass/branches/releasebranch_7_0/scripts/db.dropcolumn/db.dropcolumn.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/db.dropcolumn/db.dropcolumn.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/db.dropcolumn/db.dropcolumn.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -39,7 +39,9 @@
 import os
 import string
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     table = options['table']
     column = options['column']
@@ -98,9 +100,11 @@
     else:
 	sql = "ALTER TABLE %s DROP COLUMN %s" % (table, column)
 
-    if grass.write_command('db.execute', input = '-', database = database, driver = driver,
-			   stdin = sql) != 0:
-	grass.fatal(_("Cannot continue (problem deleting column)"))
+    try:
+        grass.write_command('db.execute', input = '-', database = database,
+                               driver = driver, stdin = sql)
+    except CalledModuleError:
+        grass.fatal(_("Cannot continue (problem deleting column)"))
 
     return 0
 

Modified: grass/branches/releasebranch_7_0/scripts/db.in.ogr/db.in.ogr.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/db.in.ogr/db.in.ogr.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/db.in.ogr/db.in.ogr.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -50,10 +50,11 @@
 #% required : no
 #%end
 
-import sys
 import os
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     dsn = options['dsn']
     db_table = options['db_table']
@@ -85,13 +86,15 @@
     else:
 	layer = None
 
-    if grass.run_command('v.in.ogr', flags = 'o', dsn = dsn, output = output,
-			 layer = layer, quiet = True) != 0:
-	if db_table:
-	    grass.fatal(_("Input table <%s> not found or not readable") % input)
-	else:
-	    grass.fatal(_("Input DSN <%s> not found or not readable") % input)
-    
+    try:
+        grass.run_command('v.in.ogr', flags='o', dsn=dsn, output=output,
+                          layer=layer, quiet=True)
+    except CalledModuleError:
+        if db_table:
+            grass.fatal(_("Input table <%s> not found or not readable") % input)
+        else:
+            grass.fatal(_("Input DSN <%s> not found or not readable") % input)
+
     # rename ID col if requested from cat to new name
     if key:
 	grass.write_command('db.execute', quiet = True,

Modified: grass/branches/releasebranch_7_0/scripts/db.out.ogr/db.out.ogr.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/db.out.ogr/db.out.ogr.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/db.out.ogr/db.out.ogr.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -56,7 +56,9 @@
 import os
 from grass.script.utils import try_remove, basename
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     input = options['input']
     layer = options['layer']
@@ -78,14 +80,21 @@
 	grass.fatal(_("File <%s> already exists") % dbffile)
 
     if olayer:
-	if grass.run_command('v.out.ogr', quiet = True, input = input, layer = layer,
-			     dsn = dsn,
-			     format = format, type = 'point,line,area', olayer = olayer) != 0:
-	    sys.exit(1)
+        try:
+            grass.run_command('v.out.ogr', quiet=True, input=input, layer=layer,
+                              dsn=dsn,
+                              format=format, type='point,line,area',
+                              olayer=olayer)
+        except CalledModuleError:
+            grass.fatal(_("Module <%s> failed") % 'v.out.ogr')
+
     else:
-	if grass.run_command('v.out.ogr', quiet = True, input = input, layer = layer,
-			     dsn = dsn, format = format, type = 'point,line,area') != 0:
-	    sys.exit(1)
+        try:
+            grass.run_command('v.out.ogr', quiet=True, input=input,
+                              layer=layer, dsn=dsn,
+                              format=format, type='point,line,area')
+        except CalledModuleError:
+            grass.fatal(_("Module <%s> failed") % 'v.out.ogr')
 
     if format == "ESRI_Shapefile":
 	exts = ['shp', 'shx', 'prj']

Modified: grass/branches/releasebranch_7_0/scripts/db.test/db.test.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/db.test/db.test.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/db.test/db.test.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -30,6 +30,7 @@
 import os
 from grass.script import core as grass
 from grass.script import db as grassdb
+from grass.exceptions import CalledModuleError
 
 def main():
     test_file = options['test']
@@ -54,17 +55,18 @@
 
 	# Copy expected result to temp file
 
-	if type == 'X':
-	    r = grass.write_command('db.execute', input = '-', stdin = sql + '\n')
-	else:
-	    resf = file(result, 'w')
-	    r = grass.write_command('db.select', input = '-', flags = 'c', stdin = sql + '\n', stdout = resf)
-	    resf.close()
+        try:
+            if type == 'X':
+                grass.write_command('db.execute', input = '-', stdin = sql + '\n')
+            else:
+                resf = file(result, 'w')
+                grass.write_command('db.select', input = '-', flags = 'c', stdin = sql + '\n', stdout = resf)
+                resf.close()
 
-	if r != 0:
-	    grass.error("EXECUTE: ******** ERROR ********")
-	else:
-	    grass.message(_("EXECUTE: OK"))
+        except CalledModuleError:
+            grass.error("EXECUTE: ******** ERROR ********")
+        else:
+            grass.message(_("EXECUTE: OK"))
 
 	expf = file(expected, 'w')
 	while True:

Modified: grass/branches/releasebranch_7_0/scripts/g.extension.all/g.extension.all.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/g.extension.all/g.extension.all.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/g.extension.all/g.extension.all.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -45,7 +45,9 @@
     import elementtree.ElementTree as etree # Python <= 2.4
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def get_extensions():
     addon_base = os.getenv('GRASS_ADDON_BASE')
     if not addon_base:
@@ -109,10 +111,12 @@
         else:
             operation = 'add'
             operation_flags = ''
-        if 0 != grass.run_command('g.extension', flags = operation_flags,
-                                  extension = ext, operation = operation):
+        try:
+            grass.run_command('g.extension', flags=operation_flags,
+                              extension=ext, operation=operation)
+        except CalledModuleError:
             grass.error(_("Unable to process extension:%s") % ext)
-    
+
     return 0
 
 if __name__ == "__main__":

Modified: grass/branches/releasebranch_7_0/scripts/i.in.spotvgt/i.in.spotvgt.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/i.in.spotvgt/i.in.spotvgt.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/i.in.spotvgt/i.in.spotvgt.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -45,12 +45,13 @@
 #% required : no
 #%end
 
-import sys
 import os
 import atexit
 import string
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 vrt = """<VRTDataset rasterXSize="$XSIZE" rasterYSize="$YSIZE">
  <SRS>GEOGCS["wgs84",DATUM["WGS_1984",SPHEROID["wgs84",6378137,298.257223563],TOWGS84[0.000,0.000,0.000]],PRIMEM["Greenwich",0],UNIT["degree",0.0174532925199433]]</SRS>
    <GeoTransform>$WESTCORNER, $RESOLUTION, 0.0000000000000000e+00, $NORTHCORNER, 0.0000000000000e+00, -$RESOLUTION</GeoTransform>
@@ -154,8 +155,10 @@
 
     ## let's import the NDVI map...
     grass.message(_("Importing SPOT VGT NDVI map..."))
-    if grass.run_command('r.in.gdal', input = vrtfile, output = name) != 0:
-	grass.fatal(_("An error occurred. Stop."))
+    try:
+        grass.run_command('r.in.gdal', input=vrtfile, output=name)
+    except CalledModuleError:
+        grass.fatal(_("An error occurred. Stop."))
 
     grass.message(_("Imported SPOT VEGETATION NDVI map <%s>.") % name)
 
@@ -223,8 +226,10 @@
 
 	## let's import the SM quality map...
 	smfile = name + '.sm'
-	if grass.run_command('r.in.gdal', input = vrtfile, output = smfile) != 0:
-	    grass.fatal(_("An error occurred. Stop."))
+        try:
+            grass.run_command('r.in.gdal', input=vrtfile, output=smfile)
+        except CalledModuleError:
+            grass.fatal(_("An error occurred. Stop."))
 
 	# some of the possible values:
 	rules = [r + '\n' for r in [

Modified: grass/branches/releasebranch_7_0/scripts/r.fillnulls/r.fillnulls.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/r.fillnulls/r.fillnulls.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/r.fillnulls/r.fillnulls.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -90,6 +90,7 @@
 import atexit
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
 tmp_rmaps = list()
 tmp_vmaps = list()
@@ -169,31 +170,41 @@
         # to ignore MASKed original values
         if usermask:
             grass.message(_("Restoring user mask (MASK)..."))
-            if grass.run_command('g.rename', quiet = quiet, rast = (usermask, 'MASK')) != 0:
+            try:
+                grass.run_command('g.rename', quiet=quiet, rast=(usermask, 'MASK'))
+            except CalledModuleError:
                 grass.warning(_("Failed to restore user MASK!"))
             usermask = None
     
         # grow identified holes by X pixels
         grass.message(_("Growing NULL areas"))
         tmp_rmaps.append(prefix + 'grown')
-        if grass.run_command('r.grow', input = prefix + 'nulls', radius = edge + 0.01,
-                             old = 1, new = 1, out = prefix + 'grown', quiet = quiet) != 0:
+        try:
+            grass.run_command('r.grow', input=prefix + 'nulls',
+                              radius=edge + 0.01, old=1, new=1,
+                              out=prefix + 'grown', quiet=quiet)
+        except CalledModuleError:
             grass.fatal(_("abandoned. Removing temporary map, restoring user mask if needed:"))
-        
+
         # assign unique IDs to each hole or hole system (holes closer than edge distance)
         grass.message(_("Assigning IDs to NULL areas"))
         tmp_rmaps.append(prefix + 'clumped')
-        if grass.run_command('r.clump', input = prefix + 'grown', output = prefix + 'clumped', quiet = quiet) != 0:
+        try:
+            grass.run_command('r.clump', input=prefix + 'grown', output=prefix + 'clumped', quiet=quiet)
+        except CalledModuleError:
             grass.fatal(_("abandoned. Removing temporary map, restoring user mask if needed:"))
-        
+
         # get a list of unique hole cat's
         grass.mapcalc("$out = if(isnull($inp), null(), $clumped)",
                         out = prefix + 'holes', inp = prefix + 'nulls', clumped = prefix + 'clumped')
         tmp_rmaps.append(prefix + 'holes')
         
         # use new IDs to identify holes
-        if grass.run_command('r.to.vect', flags = 'v', input = prefix + 'holes', output = prefix + 'holes',
-                            type = 'area', quiet = quiet) != 0:
+        try:
+            grass.run_command('r.to.vect', flags='v',
+                              input=prefix + 'holes', output=prefix + 'holes',
+                              type='area', quiet=quiet)
+        except:
             grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
         tmp_vmaps.append(prefix + 'holes')
         
@@ -220,20 +231,31 @@
             grass.message(_("Filling hole %s of %s") % (hole_n, len(cat_list)))
             hole_n = hole_n + 1
             # cut out only CAT hole for processing
-            if grass.run_command('v.extract', input = prefix + 'holes', output = holename + '_pol',
-                                cats = cat, quiet = quiet) != 0:
+            try:
+                grass.run_command('v.extract', input=prefix + 'holes',
+                                  output=holename + '_pol',
+                                  cats=cat, quiet=quiet)
+            except CalledModuleError:
                 grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
             tmp_vmaps.append(holename + '_pol')
             
             # zoom to specific hole with a buffer of two cells around the hole to remove rest of data
-            if grass.run_command('g.region', vect = holename + '_pol', align = input, 
-                                w = 'w-%d' % (edge * 2 * ew_res), e = 'e+%d' % (edge * 2 * ew_res), 
-                                n = 'n+%d' % (edge * 2 * ns_res), s = 's-%d' % (edge * 2 * ns_res),
-                                quiet = quiet) != 0:
+            try:
+                grass.run_command('g.region',
+                                  vect=holename + '_pol', align=input, 
+                                  w = 'w-%d' % (edge * 2 * ew_res),
+                                  e = 'e+%d' % (edge * 2 * ew_res), 
+                                  n = 'n+%d' % (edge * 2 * ns_res),
+                                  s = 's-%d' % (edge * 2 * ns_res),
+                                  quiet=quiet)
+            except CalledModuleError:
                 grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
             
             # remove temporary map to not overfill disk
-            if grass.run_command('g.remove', flags='bf', type='vect', name=holename + '_pol', quiet=quiet) != 0:
+            try:
+                grass.run_command('g.remove', flags='fb', type='vect',
+                                  name=holename + '_pol', quiet=quiet)
+            except CalledModuleError:
                 grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
             tmp_vmaps.remove(holename + '_pol')
             
@@ -248,8 +270,10 @@
             
             # grow hole border to get it's edge area
             tmp_rmaps.append(holename + '_grown')
-            if grass.run_command('r.grow', input = holename, radius = edge + 0.01,
-                             old = -1, out = holename + '_grown', quiet = quiet) != 0:
+            try:
+                grass.run_command('r.grow', input=holename, radius=edge + 0.01,
+                             old=-1, out=holename + '_grown', quiet=quiet)
+            except CalledModuleError:
                 grass.fatal(_("abandoned. Removing temporary map, restoring user mask if needed:"))
             
             # no idea why r.grow old=-1 doesn't replace existing values with NULL
@@ -259,8 +283,11 @@
             
             # convert to points for interpolation
             tmp_vmaps.append(holename)
-            if grass.run_command('r.to.vect', input = holename + '_edges', output = holename,
-                                type = 'point', flags = 'z', quiet = quiet) != 0:
+            try:
+                grass.run_command('r.to.vect',
+                                  input=holename + '_edges', output=holename,
+                                  type='point', flags='z', quiet=quiet)
+            except CalledModuleError:
                 grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
             
             # count number of points to control segmax parameter for interpolation:
@@ -279,9 +306,12 @@
             
             # launch v.surf.rst
             tmp_rmaps.append(holename + '_dem')
-            if grass.run_command('v.surf.rst', quiet = quiet, input = holename, elev = holename + '_dem',
-                                 tension = tension, smooth = smooth, 
-                                 segmax = segmax, npmin = npmin) != 0:
+            try:
+                grass.run_command('v.surf.rst', quiet=quiet,
+                                  input=holename, elev=holename + '_dem',
+                                  tension=tension, smooth=smooth, 
+                                  segmax=segmax, npmin=npmin)
+            except CalledModuleError:
                 # GTC Hole is NULL area in a raster map
                 grass.fatal(_("Failed to fill hole %s") % cat)
             
@@ -312,8 +342,11 @@
                 grass.run_command('g.region', align = input, rast = (filling, holename + '_dem'), quiet = quiet)
                 grass.mapcalc("$out = if(isnull($inp), if(isnull($fill), null(), $fill), $dem)", 
                                 out = filling + '_tmp', inp = holename, dem = holename + '_dem', fill = filling)
-                if grass.run_command('g.rename', rast = (filling + '_tmp', filling), 
-                                    overwrite = True, quiet = quiet) != 0:
+                try:
+                    grass.run_command('g.rename',
+                                      rast=(filling + '_tmp', filling),
+                                      overwrite=True, quiet=quiet)
+                except CalledModuleError:
                     grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
                 tmp_rmaps.remove(filling + '_tmp') # this map has been removed. No need for later cleanup.
             
@@ -325,15 +358,23 @@
                 tmp_rmaps.remove(holename + '_dem')
             except:
                 pass
-            if grass.run_command('g.remove', quiet=quiet, flags='bf',
-                type='rast', name=(holename, holename + '_grown', holename + '_edges', holename + '_dem')) != 0:
+            try:
+                grass.run_command('g.remove', quiet=quiet,
+                                  flags='fb', type='rast',
+                                  name=(holename,
+                                        holename + '_grown',
+                                        holename + '_edges',
+                                        holename + '_dem'))
+            except CalledModuleError:
                 grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
             try:
                 tmp_vmaps.remove(holename)
             except:
                 pass
-            if grass.run_command('g.remove', quiet=quiet, flags='bf',
-                type='vect', name=holename) != 0:
+            try:
+                grass.run_command('g.remove', quiet=quiet, flags='fb',
+                                  type='vect', name=holename)
+            except CalledModuleError:
                 grass.fatal(_("abandoned. Removing temporary maps, restoring user mask if needed:"))
     
     #check if method is different from rst to use r.resamp.bspline
@@ -361,7 +402,9 @@
     # restoring user's mask, if present:
     if usermask:
         grass.message(_("Restoring user mask (MASK)..."))
-        if grass.run_command('g.rename', quiet = quiet, rast = (usermask, 'MASK')) != 0:
+        try:
+            grass.run_command('g.rename', quiet=quiet, rast=(usermask, 'MASK'))
+        except CalledModuleError:
             grass.warning(_("Failed to restore user MASK!"))
         usermask = None
 

Modified: grass/branches/releasebranch_7_0/scripts/r.grow/r.grow.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/r.grow/r.grow.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/r.grow/r.grow.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -63,7 +63,9 @@
 import atexit
 import math
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 # what to do in case of user break:
 def cleanup():
     for map in [temp_dist, temp_val]:
@@ -107,8 +109,10 @@
     if not grass.find_file(input)['file']:
         grass.fatal(_("Raster map <%s> not found") % input)
 
-    if grass.run_command('r.grow.distance',  input = input, metric = metric,
-                      distance = temp_dist, value = temp_val) != 0:
+    try:
+        grass.run_command('r.grow.distance', input=input, metric=metric,
+                          distance=temp_dist, value=temp_val)
+    except CalledModuleError:
         grass.fatal(_("Growing failed. Removing temporary maps."))
 
     grass.mapcalc(

Modified: grass/branches/releasebranch_7_0/scripts/r.in.srtm/r.in.srtm.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/r.in.srtm/r.in.srtm.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/r.in.srtm/r.in.srtm.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -102,12 +102,13 @@
     'UNIT["degree",0.0174532925199433]',
     ']'])
 
-import sys
 import os
 import shutil
 import atexit
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def cleanup():
     if not in_temp:
 	return
@@ -226,8 +227,10 @@
     outf.write(proj)
     outf.close()
 
-    if grass.run_command('r.in.gdal', input = bilfile, out = tileout) != 0:
-	grass.fatal(_("Unable to import data"))
+    try:
+        grass.run_command('r.in.gdal', input=bilfile, out=tileout)
+    except:
+        grass.fatal(_("Unable to import data"))
 
     # nice color table
     grass.run_command('r.colors', map = tileout, color = 'srtm')

Modified: grass/branches/releasebranch_7_0/scripts/r.in.wms/wms_base.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/r.in.wms/wms_base.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/r.in.wms/wms_base.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -22,7 +22,9 @@
 from httplib import HTTPException
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 class WMSBase:
     def __init__(self):
         # these variables are information for destructor
@@ -439,20 +441,21 @@
     def __del__(self):
         # removes temporary mask, used for import transparent or warped temp_map
         if self.cleanup_mask:
-            # clear temporary mask, which was set by module      
-            if grass.run_command('r.mask',
-                                 quiet = True,
-                                 flags = 'r') != 0:  
+            # clear temporary mask, which was set by module
+            try:
+                grass.run_command('r.mask', quiet=True, flags='r')
+            except CalledModuleError:
                 grass.fatal(_('%s failed') % 'r.mask')
-            
+
             # restore original mask, if exists 
             if grass.find_file(self.opt_output + self.original_mask_suffix, element = 'cell', mapset = '.' )['name']:
-                if grass.run_command('g.copy',
-                                     quiet = True,
-                                     rast =  self.opt_output + self.original_mask_suffix + ',MASK') != 0:
+                try:
+                    mask_copy = self.opt_output + self.original_mask_suffix
+                    grass.run_command('g.copy', quiet=True,
+                                      rast=mask_copy + ',MASK')
+                except CalledModuleError:
                     grass.fatal(_('%s failed') % 'g.copy')
-        
-        
+
         # remove temporary created rasters
         if self.cleanup_layers: 
             maps = []
@@ -476,13 +479,13 @@
         """!Import raster into GRASS.
         """
         # importing temp_map into GRASS
-        if grass.run_command('r.in.gdal',
-                             quiet = True,
-                             overwrite = True,
-                             input = raster,
-                             output = self.opt_output) != 0:
+        try:
+            grass.run_command('r.in.gdal',
+                              quiet=True, overwrite=True,
+                              input=raster, output=self.opt_output)
+        except CalledModuleError:
             grass.fatal(_('%s failed') % 'r.in.gdal')
-        
+
         # information for destructor to cleanup temp_layers, created
         # with r.in.gdal
         self.cleanup_layers = True
@@ -500,30 +503,34 @@
         if grass.find_file( self.opt_output + '.alpha', element = 'cell', mapset = '.' )['name']:
             # saving current mask (if exists) into temp raster
             if grass.find_file('MASK', element = 'cell', mapset = '.' )['name']:
-                if grass.run_command('g.copy',
-                                     quiet = True,
-                                     rast = 'MASK,' + self.opt_output + self.original_mask_suffix) != 0:    
+                try:
+                    mask_copy = self.opt_output + self.original_mask_suffix
+                    grass.run_command('g.copy', quiet=True,
+                                      rast='MASK,' + mask_copy)
+                except CalledModuleError:
                     grass.fatal(_('%s failed') % 'g.copy')
-            
+
             # info for destructor
             self.cleanup_mask = True
-            if grass.run_command('r.mask',
-                                 quiet = True,
-                                 overwrite = True,
-                                 maskcats = "0",
-                                 flags = 'i',
-                                 raster = self.opt_output + '.alpha') != 0: 
+            try:
+                grass.run_command('r.mask',
+                                  quiet=True, overwrite=True,
+                                  maskcats="0",
+                                  flags='i',
+                                  raster=self.opt_output + '.alpha')
+            except CalledModuleError:
                 grass.fatal(_('%s failed') % 'r.mask')
-        
+
         #TODO one band + alpha band?
         if grass.find_file(self.opt_output + '.red', element = 'cell', mapset = '.')['file']:
-            if grass.run_command('r.composite',
-                                 quiet = True,
-                                 overwrite = True,
-                                 red = self.opt_output + '.red',
-                                 green = self.opt_output +  '.green',
-                                 blue = self.opt_output + '.blue',
-                                 output = self.opt_output ) != 0:
+            try:
+                grass.run_command('r.composite',
+                                  quiet=True, overwrite=True,
+                                  red=self.opt_output + '.red',
+                                  green=self.opt_output + '.green',
+                                  blue=self.opt_output + '.blue',
+                                  output=self.opt_output)
+            except CalledModuleError:
                 grass.fatal(_('%s failed') % 'r.composite')
 
         grass.message(_('<%s> created.') % self.opt_output)

Modified: grass/branches/releasebranch_7_0/scripts/r.mask/r.mask.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/r.mask/r.mask.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/r.mask/r.mask.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -66,11 +66,13 @@
 #% guisection: Remove
 #%end
 
-import sys
 import os
-import grass.script as grass
 import atexit
 
+import grass.script as grass
+from grass.exceptions import CalledModuleError
+
+
 def cleanup():
     if tmp:
         grass.run_command('g.remove', type='rast', name=tmp, quiet=True, flags='f')
@@ -141,9 +143,11 @@
                 tmp_hull = "tmp_hull_%d" % os.getpid()
                 to_rast_input = tmp_hull
                 # force 'flat' convex hull for 3D vector maps
-                if 0 != grass.run_command('v.hull', flags = 'f', quiet = True,
-                                          input = vector_name, output = tmp_hull,
-                                          layer = layer, cats = cats, where = where):
+                try:
+                    grass.run_command('v.hull', flags='f', quiet=True,
+                                      input=vector_name, output=tmp_hull,
+                                      layer=layer, cats=cats, where=where)
+                except CalledModuleError:
                     grass.fatal(_("Unable to create a convex hull for vector map <%s>") % vector_name)
             else:
                 to_rast_input = vector_name

Modified: grass/branches/releasebranch_7_0/scripts/r.out.xyz/r.out.xyz.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/r.out.xyz/r.out.xyz.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/r.out.xyz/r.out.xyz.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -35,8 +35,8 @@
 
 import sys
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
-
 def main():
     # if no output filename, output to stdout
     output = options['output']
@@ -50,7 +50,11 @@
     if sep != '|':
         parameters.update(separator=sep)
 
-    ret = grass.run_command("r.stats", **parameters)
+    ret = 0
+    try:
+        grass.run_command("r.stats", **parameters)
+    except CalledModuleError:
+        ret = 1
     sys.exit(ret)
 
 if __name__ == "__main__":

Modified: grass/branches/releasebranch_7_0/scripts/r3.in.xyz/r3.in.xyz.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/r3.in.xyz/r3.in.xyz.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/r3.in.xyz/r3.in.xyz.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -175,6 +175,7 @@
 import os
 import atexit
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
 
 def cleanup():
@@ -310,7 +311,9 @@
                                 pattern='tmp.r3xyz.%d.*' % os.getpid()).rstrip(os.linesep)
     grass.debug(slices)
 
-    if grass.run_command('r.to.rast3', input=slices, output=output) is 0:
+    try:
+        grass.run_command('r.to.rast3', input=slices, output=output)
+    except CalledModuleError:
         grass.message(_("Done. 3D raster map <%s> created.") % output)
 
 

Modified: grass/branches/releasebranch_7_0/scripts/v.build.all/v.build.all.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.build.all/v.build.all.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.build.all/v.build.all.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -20,6 +20,7 @@
 
 import sys
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
 def main():
     env = grass.gisenv()
@@ -36,17 +37,20 @@
         
     i = 1
     for vect in vectors:
-	map = "%s@%s" % (vect, mapset)
-	grass.message(_("%s\nBuilding topology for vector map <%s> (%d of %d)...\n%s") % \
+        map = "%s@%s" % (vect, mapset)
+        grass.message(_("%s\nBuilding topology for vector map <%s> (%d of %d)...\n%s") % \
                           ('-' * 80, map, i, num_vectors, '-' * 80))
-	grass.verbose(_("v.build map=%s") % map)
-	if grass.run_command("v.build", map = map, quiet = quiet) != 0:
+        grass.verbose(_("v.build map=%s") % map)
+        try:
+            grass.run_command("v.build", map=map, quiet=quiet)
+        except CalledModuleError:
             grass.error(_("Building topology for vector map <%s> failed") % map)
-	    ret = 1
+            ret = 1
         i += 1
-    
+
     return ret
 
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     sys.exit(main())

Modified: grass/branches/releasebranch_7_0/scripts/v.convert.all/v.convert.all.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.convert.all/v.convert.all.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.convert.all/v.convert.all.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -23,7 +23,9 @@
 
 import sys
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     env = grass.gisenv()
     mapset = env['MAPSET']
@@ -32,11 +34,13 @@
     for vect in grass.list_grouped('oldvect')[mapset]:
 	inmap = "%s@%s" % (vect, mapset)
 	outmap = vect.replace(".", "_")
-	if grass.run_command("v.convert", input = inmap, output = outmap) == 0:
-	    converted += 1
-	else:
-	    grass.warning(_("Error converting map <%s> to <%s>") % (inmap, outmap))
-	    ret = 1
+        try:
+            grass.run_command("v.convert", input=inmap, output=outmap)
+        except CalledModuleError:
+            grass.warning(_("Error converting map <%s> to <%s>") % (inmap, outmap))
+            ret = 1
+        else:
+            converted += 1
 
 	if converted < 1:
 	    grass.warning(_("No vector maps converted as no old vector maps present in current mapset."))

Modified: grass/branches/releasebranch_7_0/scripts/v.db.addtable/v.db.addtable.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.db.addtable/v.db.addtable.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.db.addtable/v.db.addtable.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -55,7 +55,9 @@
 import sys
 import os
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     vector = options['map']
     table = options['table']
@@ -116,9 +118,12 @@
         grass.verbose(_("Creating table with columns (%s)...") % column_def)
         
         sql = "CREATE TABLE %s (%s)" % (table, column_def)
-        if grass.run_command('db.execute', database = database, driver = driver, sql = sql) != 0:
+        try:
+            grass.run_command('db.execute',
+                              database=database, driver=driver, sql=sql)
+        except CalledModuleError:
             grass.fatal(_("Unable to create table <%s>") % table)
-    
+
     # connect the map to the DB:
     if schema is not '':
         table = '%s.%s' (schema, table)

Modified: grass/branches/releasebranch_7_0/scripts/v.db.dropcolumn/v.db.dropcolumn.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.db.dropcolumn/v.db.dropcolumn.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.db.dropcolumn/v.db.dropcolumn.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -41,7 +41,9 @@
 import os
 import string
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     map    = options['map']
     layer  = options['layer']
@@ -103,9 +105,11 @@
             sql = tmpl.substitute(table = table, coldef = coltypes, colnames = colnames, keycol = keycol)
         else:
             sql = "ALTER TABLE %s DROP COLUMN %s" % (table, column)
-        
-        if grass.write_command('db.execute', input = '-', database = database, driver = driver,
-                              stdin = sql) != 0:
+
+        try:
+            grass.write_command('db.execute', input = '-', database = database, driver = driver,
+                                stdin = sql)
+        except CalledModuleError:
             grass.fatal(_("Deleting column failed"))
     
     # write cmd history:

Modified: grass/branches/releasebranch_7_0/scripts/v.db.droprow/v.db.droprow.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.db.droprow/v.db.droprow.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.db.droprow/v.db.droprow.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -37,14 +37,17 @@
 
 import sys
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     # delete vectors via reverse selection
-    ret = grass.run_command('v.extract',
-                            flags = 'r',
-                            input = options['input'], layer = options['layer'],
-                            output = options['output'], where = options['where'])
-    if ret != 0:
+    try:
+        grass.run_command('v.extract',
+                          flags='r',
+                          input=options['input'], layer=options['layer'],
+                          output=options['output'], where=options['where'])
+    except CalledModuleError:
         return 1
 
     # write cmd history:

Modified: grass/branches/releasebranch_7_0/scripts/v.db.droptable/v.db.droptable.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.db.droptable/v.db.droptable.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.db.droptable/v.db.droptable.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -37,7 +37,9 @@
 import sys
 import os
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     force = flags['f']
     map = options['map']
@@ -73,20 +75,24 @@
 
     grass.message(_("Dropping table <%s>...") % table)
 
-    if grass.write_command('db.execute', stdin = "DROP TABLE %s" % table, input = '-',
-                           database = database, driver = driver) != 0:
-	grass.fatal(_("An error occurred while running db.execute"))
+    try:
+        grass.write_command('db.execute', stdin="DROP TABLE %s" % table,
+                            input='-', database=database, driver=driver)
+    except CalledModuleError:
+        grass.fatal(_("An error occurred while running db.execute"))
 
     grass.run_command('v.db.connect', flags = 'd', map = map, layer = layer)
 
     grass.message(_("Current attribute table link(s):")) 
     # silently test first to avoid confusing error messages
     nuldev = file(os.devnull, 'w')
-    if grass.run_command('v.db.connect', flags ='p', map = map, quiet = True,
-			 stdout = nuldev, stderr = nuldev) != 0:
-	grass.message(_("(No database links remaining)"))
+    try:
+        grass.run_command('v.db.connect', flags='p', map=map, quiet=True,
+                          stdout=nuldev, stderr=nuldev)
+    except CalledModuleError:
+        grass.message(_("(No database links remaining)"))
     else:
-	grass.run_command('v.db.connect', flags ='p', map = map)
+        grass.run_command('v.db.connect', flags='p', map=map)
 
     # write cmd history:
     grass.vector_history(map)

Modified: grass/branches/releasebranch_7_0/scripts/v.db.join/v.db.join.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.db.join/v.db.join.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.db.join/v.db.join.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -57,10 +57,11 @@
 #%end
 
 import sys
-import os
 import string
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     map = options['map']
     layer = options['layer']
@@ -132,16 +133,22 @@
 
 	# add only the new column to the table
 	if colname not in all_cols_tt:
-	    if grass.run_command('v.db.addcolumn', map = map, columns = colspec, layer = layer) != 0:
-	        grass.fatal(_("Error creating column <%s>") % colname)
+            try:
+                grass.run_command('v.db.addcolumn', map=map,
+                                  columns=colspec, layer=layer)
+            except CalledModuleError:
+                grass.fatal(_("Error creating column <%s>") % colname)
 
 	stmt = template.substitute(table = maptable, column = column,
 				   otable = otable, ocolumn = ocolumn,
 				   colname = colname)
         grass.debug(stmt, 1)
         grass.verbose(_("Updating column <%s> of vector map <%s>...") % (colname, map))
-	if grass.write_command('db.execute', stdin = stmt, input = '-', database = database, driver = driver) != 0:
-	    grass.fatal(_("Error filling column <%s>") % colname)
+        try:
+            grass.write_command('db.execute', stdin=stmt, input='-',
+                                database=database, driver=driver)
+        except CalledModuleError:
+            grass.fatal(_("Error filling column <%s>") % colname)
 
     # write cmd history
     grass.vector_history(map)

Modified: grass/branches/releasebranch_7_0/scripts/v.db.reconnect.all/v.db.reconnect.all.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.db.reconnect.all/v.db.reconnect.all.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.db.reconnect.all/v.db.reconnect.all.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -54,6 +54,7 @@
 import string
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
 # substitute variables (gisdbase, location_name, mapset)
 def substitute_db(database):
@@ -88,8 +89,10 @@
 
     grass.info(_("Target database doesn't exist, "
                  "creating a new database using <%s> driver...") % driver)
-    if 0 != grass.run_command('db.createdb', driver = driver,
-                              database = subst_database):
+    try:
+        grass.run_command('db.createdb', driver = driver,
+                          database = subst_database)
+    except CalledModuleError:
         grass.fatal(_("Unable to create database <%s> by driver <%s>") % \
                         (subst_database, driver))
         
@@ -105,11 +108,13 @@
         return False
     
     grass.info("Copying table <%s> to target database..." % to_table)
-    if 0 != grass.run_command('db.copy', from_driver = from_driver,
-                              from_database = from_database,
-                              from_table = from_table, to_driver = to_driver,
-                              to_database = to_database,
-                              to_table = to_table):
+    try:
+        grass.run_command('db.copy', from_driver = from_driver,
+                          from_database = from_database,
+                          from_table = from_table, to_driver = to_driver,
+                          to_database = to_database,
+                          to_table = to_table)
+    except CalledModuleError:
         grass.fatal(_("Unable to copy table <%s>") % from_table)
     
     return True
@@ -117,13 +122,17 @@
 # drop tables if required (-d)
 def drop_tab(vector, layer, table, driver, database):
     # disconnect
-    if 0 != grass.run_command('v.db.connect', flags = 'd', quiet = True, map = vector,
-			      layer = layer, table = table):
-	grass.warning(_("Unable to disconnect table <%s> from vector <%s>") % (table, vector))
+    try:
+        grass.run_command('v.db.connect', flags = 'd', quiet = True, map = vector,
+			          layer = layer, table = table)
+    except CalledModuleError:
+        grass.warning(_("Unable to disconnect table <%s> from vector <%s>") % (table, vector))
     # drop table
-    if 0 != grass.run_command('db.droptable', quiet = True, flags = 'f',
-                              driver = driver, database = database,
-                              table = table):
+    try:
+        grass.run_command('db.droptable', quiet = True, flags = 'f',
+                          driver = driver, database = database,
+                          table = table)
+    except CalledModuleError:
         grass.fatal(_("Unable to drop table <%s>") % table)
         
 # create index on key column
@@ -132,9 +141,11 @@
 	return False
 
     grass.info(_("Creating index <%s>...") % index_name)
-    if 0 != grass.run_command('db.execute', quiet = True,
-                              driver = driver, database = database,
-                              sql = "create unique index %s on %s(%s)" % (index_name, table, key)):
+    try:
+        grass.run_command('db.execute', quiet = True,
+                          driver = driver, database = database,
+                          sql = "create unique index %s on %s(%s)" % (index_name, table, key))
+    except CalledModuleError:
         grass.warning(_("Unable to create index <%s>") % index_name)
 
 def main():
@@ -228,9 +239,11 @@
 
                 # reconnect tables (don't use substituted new_database)
 		# NOTE: v.db.connect creates an index on the key column
-                if 0 != grass.run_command('v.db.connect', flags = 'o', quiet = True, map = vect,
-                                          layer = layer, driver = new_driver, database = new_database,
-                                          table = new_schema_table, key = key):
+                try:
+                    grass.run_command('v.db.connect', flags = 'o', quiet = True, map = vect,
+                                      layer = layer, driver = new_driver, database = new_database,
+                                      table = new_schema_table, key = key)
+                except CalledModuleError:
                     grass.warning(_("Unable to connect table <%s> to vector <%s> on layer <%s>") %
 				  (table, vect, str(layer)))
 

Modified: grass/branches/releasebranch_7_0/scripts/v.dissolve/v.dissolve.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.dissolve/v.dissolve.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.dissolve/v.dissolve.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -37,7 +37,9 @@
 import atexit
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def cleanup():
     nuldev = file(os.devnull, 'w')
     grass.run_command('g.remove', type='vect', name='%s_%s' % (output, tmp), quiet=True, flags='f', stderr=nuldev)
@@ -82,10 +84,15 @@
 
 	tmpfile = '%s_%s' % (output, tmp)
 
-	if grass.run_command('v.reclass', input = input, output = tmpfile,
-                             layer = layer, column = column) == 0:
-            grass.run_command('v.extract', flags = 'd', input = tmpfile,
-                              output = output, type = 'area', layer = layer)
+        try:
+            grass.run_command('v.reclass', input=input, output=tmpfile,
+                              layer=layer, column=column)
+            grass.run_command('v.extract', flags='d', input=tmpfile,
+                              output=output, type='area', layer=layer)
+        except CalledModuleError, e:
+            grass.fatal(_("Final extraction steps failed."
+                          " Check above error messages and"
+                          " see following details:\n%s") % e)
 
     # write cmd history:
     grass.vector_history(output)

Modified: grass/branches/releasebranch_7_0/scripts/v.in.e00/v.in.e00.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.in.e00/v.in.e00.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.in.e00/v.in.e00.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -37,13 +37,14 @@
 #% required : no
 #%end
 
-import sys
 import os
 import shutil
 import glob
 from grass.script.utils import try_rmdir, try_remove, basename
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
     filename = options['file']
     type = options['type']
@@ -131,10 +132,12 @@
     layer = dict(point = 'LAB', line = 'ARC', area = ['LAB','ARC'])
     itype = dict(point = 'point', line = 'line', area = 'centroid')
 
-    if grass.run_command('v.in.ogr', flags = 'o', dsn = e00shortname,
-			 layer = layer[type], type = itype[type],
-			 output = name) != 0:
-	grass.fatal(_("An error occurred while running v.in.ogr"))
+    try:
+        grass.run_command('v.in.ogr', flags='o', dsn=e00shortname,
+                          layer=layer[type], type=itype[type],
+                          output=name)
+    except CalledModuleError:
+        grass.fatal(_("An error occurred while running v.in.ogr"))
 
     grass.message(_("Imported <%s> vector map <%s>.") % (type, name))
 

Modified: grass/branches/releasebranch_7_0/scripts/v.in.gps/v.in.gps.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.in.gps/v.in.gps.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.in.gps/v.in.gps.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -86,7 +86,9 @@
 import re
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 #.... todo ....
 
 def main():
@@ -168,13 +170,13 @@
     grass.verbose("Importing data ...")
 
     tmp_gpx = tmp + ".gpx"
-    ret = grass.run_command('v.in.ogr', dsn = tmp_gpx, output = output,
-			    type = type, format = 'GPX', lco = linetype,
-			    dsco = "GPX_USE_EXTENSIONS=YES", quiet = True)
-    if ret != 0:
-	grass.fatal(_("Error importing data"))
+    try:
+        grass.run_command('v.in.ogr', dsn=tmp_gpx, output=output,
+                          type=type, format='GPX', lco=linetype,
+                          dsco="GPX_USE_EXTENSIONS=YES", quiet=True)
+    except CalledModuleError:
+        grass.fatal(_("Error importing data"))
 
-
     #### set up projection info
     # TODO: check if we are already in ll/WGS84.  If so skip m.proj step.
 

Modified: grass/branches/releasebranch_7_0/scripts/v.in.mapgen/v.in.mapgen.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.in.mapgen/v.in.mapgen.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.in.mapgen/v.in.mapgen.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -52,7 +52,9 @@
 import shutil
 from grass.script.utils import try_remove
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
+
 def cleanup():
     try_remove(tmp)
     try_remove(tmp + '.dig')
@@ -193,8 +195,10 @@
     else:
         #### import to binary vector file
         grass.message(_("Importing with v.in.ascii...")) 
-        if grass.run_command('v.in.ascii', flags = do3D, input = digfile,
-                             output = name, format = 'standard') != 0:
+        try:
+            grass.run_command('v.in.ascii', flags=do3D, input=digfile,
+                              output=name, format='standard')
+        except CalledModuleError:
             grass.fatal(_('An error occurred on creating "%s", please check') % name)
 
 if __name__ == "__main__":

Modified: grass/branches/releasebranch_7_0/scripts/v.in.wfs/v.in.wfs.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.in.wfs/v.in.wfs.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.in.wfs/v.in.wfs.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -137,14 +137,15 @@
 
 
     grass.message(_("Importing data..."))
-    ret = grass.run_command('v.in.ogr', flags = 'o', dsn = tmpxml, out = out)
-    try_remove(tmpxml)
-    
-    if ret == 0:
+    try:
+        grass.run_command('v.in.ogr', flags='o', dsn=tmpxml, out=out)
         grass.message(_("Vector points map <%s> imported from WFS.") % out)
-    else:
+    except:
         grass.message(_("WFS import failed"))
+    finally:
+        try_remove(tmpxml)
 
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()

Modified: grass/branches/releasebranch_7_0/scripts/v.out.gps/v.out.gps.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.out.gps/v.out.gps.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.out.gps/v.out.gps.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -82,11 +82,12 @@
 import sys
 import os
 import atexit
-import string
 import re
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
+
 def cleanup():
     grass.verbose("Cleaning up ...")
     if tmp:
@@ -158,11 +159,12 @@
     if where:
 	grass.verbose("Extracting data ...")
 	tmp_extr = "tmp_vogb_extr_%d" % os.getpid()
-	ret = grass.run_command('v.extract', input = "$GIS_OPT_INPUT",
-				output = tmp_extr, type = type, layer = layer,
-				where = where, quiet = True)
-	if ret != 0:
-	    grass.fatal(_("Error executing SQL query"))
+        try:
+            grass.run_command('v.extract', input="$GIS_OPT_INPUT",
+                              output=tmp_extr, type=type, layer=layer,
+                              where=where, quiet=True)
+        except CalledModuleError:
+            grass.fatal(_("Error executing SQL query"))
 
 	kv = grass.vector_info_topo(tmp_extr)
 	if kv['primitives'] == 0:
@@ -241,17 +243,20 @@
 	db_database = db_params['database']
 	db_driver = db_params['driver']
 
-	ret = grass.run_command('db.copy',
-				from_driver = db_driver,
-				from_database = db_database,
-				from_table = db_table,
-				to_table = tmp_vogb)
-	if ret != 0:
-	    grass.fatal(_("Error copying temporary DB"))
+        try:
+            grass.run_command('db.copy',
+                              from_driver=db_driver,
+                              from_database=db_database,
+                              from_table=db_table,
+                              to_table=tmp_vogb)
+        except CalledModuleError:
+            grass.fatal(_("Error copying temporary DB"))
 
-	ret = grass.run_command('v.db.connect', map = tmp_vogb, table = tmp_vogb, quiet = True)
-	if ret != 0:
-	    grass.fatal(_("Error reconnecting temporary DB"))
+        try:
+            grass.run_command('v.db.connect',
+                              map=tmp_vogb, table=tmp_vogb, quiet=True)
+        except CalledModuleError:
+            grass.fatal(_("Error reconnecting temporary DB"))
 
     # export as GPX using v.out.ogr
     if trk:
@@ -273,11 +278,12 @@
     grass.verbose("Exporting data ...")
 
     tmp_gpx = tmp + ".gpx"
-    ret = grass.run_command('v.out.ogr', input = tmp_vogb, dsn = tmp_gpx,
-			    type = type, format = 'GPX', lco = linetype,
-			    dsco = "GPX_USE_EXTENSIONS=YES", quiet = True)
-    if ret != 0:
-	grass.fatal(_("Error exporting data"))
+    try:
+        grass.run_command('v.out.ogr', input=tmp_vogb, dsn=tmp_gpx,
+                          type=type, format='GPX', lco=linetype,
+                          dsco="GPX_USE_EXTENSIONS=YES", quiet=True)
+    except CalledModuleError:
+        grass.fatal(_("Error exporting data"))
 
     if format == 'gpx':
 	# short circuit, we have what we came for.

Modified: grass/branches/releasebranch_7_0/scripts/v.rast.stats/v.rast.stats.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.rast.stats/v.rast.stats.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.rast.stats/v.rast.stats.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -65,6 +65,7 @@
 import os
 import atexit
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 
 
 def cleanup():
@@ -135,8 +136,10 @@
     grass.run_command('g.region', align=raster)
 
     # prepare raster MASK
-    if grass.run_command('v.to.rast', input=vector, output=rastertmp,
-                         use='cat', quiet=True) != 0:
+    try:
+        grass.run_command('v.to.rast', input=vector, output=rastertmp,
+                          use='cat', quiet=True)
+    except CalledModuleError:
         grass.fatal(_("An error occurred while converting vector to raster"))
 
     # dump cats to file to avoid "too many argument" problem:
@@ -225,8 +228,10 @@
 
     if addcols:
         grass.verbose(_("Adding columns '%s'") % addcols)
-        if grass.run_command('v.db.addcolumn', map=vector, columns=addcols,
-                             layer=layer) != 0:
+        try:
+            grass.run_command('v.db.addcolumn', map=vector, columns=addcols,
+                              layer=layer)
+        except CalledModuleError:
             grass.fatal(_("Adding columns failed. Exiting."))
 
     # calculate statistics:
@@ -276,16 +281,20 @@
     f.close()
 
     grass.message(_("Updating the database ..."))
-    exitcode = grass.run_command('db.execute', input=sqltmp,
-                                 database=fi['database'], driver=fi['driver'])
-
-    grass.run_command('g.remove', type='rast', name='MASK', quiet=True, flags='f', stderr=nuldev)
-
-    if exitcode == 0:
-        grass.verbose((_("Statistics calculated from raster map <%s>") % raster) +
-                      (_(" and uploaded to attribute table of vector map <%s>.") % vector))
-    else:
+    exitcode = 1
+    try:
+        grass.run_command('db.execute', input=sqltmp,
+                          database=fi['database'], driver=fi['driver'])
+        grass.verbose((_("Statistics calculated from raster map <{raster}>"
+                         " and uploaded to attribute table"
+                         " of vector map <{vector}>."
+                         ).format(raster=raster, vector=vector)))
+    except CalledModuleError:
         grass.warning(_("Failed to upload statistics to attribute table of vector map <%s>.") % vector)
+        exitcode = 1
+    finally:
+         grass.run_command('g.remove', flags='f', type='rast',
+                           name='MASK', quiet=True, stderr=nuldev)
 
     sys.exit(exitcode)
 

Modified: grass/branches/releasebranch_7_0/scripts/v.to.lines/v.to.lines.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.to.lines/v.to.lines.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.to.lines/v.to.lines.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -38,8 +38,8 @@
 #%end
 
 import grass.script as grass
+from grass.exceptions import CalledModuleError
 import os
-import sys
 
 
 def main():
@@ -86,27 +86,35 @@
     input_tmp = '{inp}_tmp_{pid}'.format(inp=input, pid=pid)
     remove_names = "%s,%s" % (out_type, input_tmp)
     grass.message(_("Processing area data (%d areas found)...") % in_info['areas'])
-    if 0 != grass.run_command('v.category', layer="2", type='boundary',
-                              option='add', input=input, out=input_tmp,
-                              quiet=quiet):
+
+    try:
+        grass.run_command('v.category', layer="2", type='boundary',
+                          option='add', input=input, out=input_tmp,
+                          quiet=quiet)
+    except CalledModuleError:
         grass.run_command('g.remove', type='vect', name=input_tmp, quiet=quiet,
                           flags='f')
         grass.fatal(_("Error creating layer 2"))
-    if 0 != grass.run_command('v.db.addtable', map=input_tmp, layer="2",
-                              columns="left integer,right integer",
-                              quiet=quiet):
+    try:
+        grass.run_command('v.db.addtable', map=input_tmp, layer="2",
+                          columns="left integer,right integer",
+                          quiet=quiet)
+    except CalledModuleError:
         grass.run_command('g.remove', type='vect', name=input_tmp, quiet=quiet,
                           flags='f')
         grass.fatal(_("Error creating new table for layer 2"))
-    if 0 != grass.run_command('v.to.db', map=input_tmp, option="sides",
-                              columns="left,right", layer="2", quiet=quiet):
+    try:
+        grass.run_command('v.to.db', map=input_tmp, option="sides",
+                          columns="left,right", layer="2", quiet=quiet)
+    except CalledModuleError:
         grass.run_command('g.remove', type='vect', name=input_tmp, quiet=quiet,
                           flags='f')
         grass.fatal(_("Error populating new table for layer 2"))
-
-    if 0 != grass.run_command('v.type', input=input_tmp, output=out_type,
-                              from_type='boundary', to_type='line',
-                              quiet=quiet, layer="2"):
+    try:
+        grass.run_command('v.type', input=input_tmp, output=out_type,
+                          from_type='boundary', to_type='line',
+                          quiet=quiet, layer="2")
+    except CalledModuleError:
         grass.run_command('g.remove', type='vect', name=remove_names,
                           quiet=quiet, flags='f')
         grass.fatal(_("Error converting polygon to line"))
@@ -118,24 +126,32 @@
             max_cat = report[0].split()[-1]
             break
     if min_cat and max_cat:
-        if 0 != grass.run_command('v.edit', map=out_type, tool='delete',
-                                  type='centroid', layer=2, quiet=quiet,
-                                  cats='{mi}-{ma}'.format(mi=min_cat, ma=max_cat)):
+        try:
+            grass.run_command('v.edit', map=out_type, tool='delete',
+                              type='centroid', layer=2, quiet=quiet,
+                              cats='{mi}-{ma}'.format(mi=min_cat, ma=max_cat))
+        except CalledModuleError:
             grass.run_command('g.remove', type='vect', name=remove_names,
                               quiet=quiet, flags='f')
             grass.fatal(_("Error removing centroids"))
 
     try:
-        if 0 != grass.run_command('v.db.droptable', map=out_type, layer=1,
-                                  flags='f', quiet=True):
+        try:
+            # TODO: fix magic numbers for layer here and there
+            grass.run_command('v.db.droptable', map=out_type, layer=1,
+                              flags='f', quiet=True)
+        except CalledModuleError:
             grass.run_command('g.remove', type='vect', name=remove_names,
                               quiet=quiet, flags='f')
             grass.fatal(_("Error removing table from layer 1"))
+    # TODO: when this except is happaning, it seems that never, so it seems wrong
     except:
         grass.warning(_("No table for layer %d" % 1))
-    if 0 != grass.run_command('v.category', input=out_type, option='transfer',
-                              output=output, layer="2,1", quiet=quiet,
-                              overwrite=overwrite):
+    try:
+        grass.run_command('v.category', input=out_type, option='transfer',
+                          output=output, layer="2,1", quiet=quiet,
+                          overwrite=overwrite)
+    except CalledModuleError:
         grass.run_command('g.remove', type='vect', name=remove_names,
                           quiet=quiet, flags='f')
         grass.fatal(_("Error adding categories"))
@@ -145,6 +161,7 @@
         grass.run_command('g.remove', type='vect', name=out_temp, quiet=quiet,
                           flags='f')
 
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()

Modified: grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.unpack/v.unpack.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -42,6 +42,7 @@
 from grass.script.utils import diff_files, try_rmdir
 from grass.script import core as grass
 from grass.script import db as grassdb
+from grass.exceptions import CalledModuleError
 
 
 def cleanup():
@@ -176,21 +177,25 @@
                                                                   to_table))
 
             # copy the table in the default database
-            if 0 != grass.run_command('db.copy', to_driver=dbconn['driver'],
-                                      to_database=todb, to_table=to_table,
-                                      from_driver='sqlite',
-                                      from_database=fromdb,
-                                      from_table=from_table):
+            try:
+                grass.run_command('db.copy', to_driver=dbconn['driver'],
+                                  to_database=todb, to_table=to_table,
+                                  from_driver='sqlite',
+                                  from_database=fromdb,
+                                  from_table=from_table)
+            except CalledModuleError:
                 grass.fatal(_("Unable to copy table <%s> as table <%s>") % (from_table, to_table))
 
             grass.verbose(_("Connect table <%s> to vector map <%s> at layer <%s>") %
                            (to_table, map_name, layer))
 
             # and connect the new tables with the right layer
-            if 0 != grass.run_command('v.db.connect', flags='o', quiet=True,
-                                      driver=dbconn['driver'], database=todb,
-                                      map=map_name, key=values[2],
-                                      layer=layer, table=to_table):
+            try:
+                grass.run_command('v.db.connect', flags='o', quiet=True,
+                                  driver=dbconn['driver'], database=todb,
+                                  map=map_name, key=values[2],
+                                  layer=layer, table=to_table)
+            except CalledModuleError:
                 grass.fatal(_("Unable to connect table <%s> to vector map <%s>") %
                              (to_table, map_name))
 

Modified: grass/branches/releasebranch_7_0/scripts/v.what.vect/v.what.vect.py
===================================================================
--- grass/branches/releasebranch_7_0/scripts/v.what.vect/v.what.vect.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/scripts/v.what.vect/v.what.vect.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -53,18 +53,26 @@
 
 import sys
 from grass.script import core as grass
+from grass.exceptions import CalledModuleError
 
+
 def main():
-    return grass.run_command("v.distance",
-                             _from = options['map'],
-                             to = options['qmap'],
-                             column = options['column'],
-                             to_column = options['qcolumn'],
-                             upload = "to_attr",
-                             dmax = options['dmax'],
-                             from_layer = options['layer'],
-                             to_layer = options['qlayer'])
-    
+    try:
+        grass.run_command('v.distance',
+                          from_=options['map'],
+                          to=options['qmap'],
+                          column=options['column'],
+                          to_column=options['qcolumn'],
+                          upload='to_attr',
+                          dmax=options['dmax'],
+                          from_layer=options['layer'],
+                          to_layer=options['qlayer'])
+    except CalledModuleError:
+        return 1
+    else:
+        return 0
+
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     sys.exit(main())

Modified: grass/branches/releasebranch_7_0/temporal/t.rast.colors/t.rast.colors.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.colors/t.rast.colors.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.colors/t.rast.colors.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -96,6 +96,7 @@
 
 import grass.script as grass
 import grass.temporal as tgis
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -162,11 +163,11 @@
         if(equi):
             flags_+="e"
 
-        ret = grass.run_command("r.colors", flags=flags_, file=filename,
-                                color=color, raster=raster, volume=volume,
-                                rules=rules, overwrite=grass.overwrite())
-
-        if ret != 0:
+        try:
+            grass.run_command("r.colors", flags=flags_, file=filename,
+                              color=color, raster=raster, volume=volume,
+                              rules=rules, overwrite=grass.overwrite())
+        except CalledModuleError:
             grass.fatal(_("Error in r.colors call"))
 
 if __name__ == "__main__":

Modified: grass/branches/releasebranch_7_0/temporal/t.rast.out.vtk/t.rast.out.vtk.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.out.vtk/t.rast.out.vtk.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.out.vtk/t.rast.out.vtk.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -67,6 +67,7 @@
 import os
 import grass.script as grass
 import grass.temporal as tgis
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -129,16 +130,17 @@
                 mflags += "c"
 
             # Export the raster map with r.out.vtk
-            if elevation:
-                ret = grass.run_command("r.out.vtk", flags=mflags, null=null,
-                                        input=map_name, elevation=elevation,
-                                        output=out_name,
-                                        overwrite=grass.overwrite())
-            else:
-                ret = grass.run_command("r.out.vtk", flags=mflags, null=null,
-                                        input=map_name, output=out_name,
-                                        overwrite=grass.overwrite())
-            if ret != 0:
+            try:
+                if elevation:
+                    grass.run_command("r.out.vtk", flags=mflags, null=null,
+                                      input=map_name, elevation=elevation,
+                                      output=out_name,
+                                      overwrite=grass.overwrite())
+                else:
+                    grass.run_command("r.out.vtk", flags=mflags, null=null,
+                                      input=map_name, output=out_name,
+                                      overwrite=grass.overwrite())
+            except CalledModuleError:
                 grass.fatal(_("Unable to export raster map <%s>" % map_name))
 
             count += 1

Modified: grass/branches/releasebranch_7_0/temporal/t.rast.series/t.rast.series.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.series/t.rast.series.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.series/t.rast.series.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -63,6 +63,7 @@
 
 import grass.script as grass
 import grass.temporal as tgis
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -100,11 +101,14 @@
         if nulls:
             flag += "n"
 
-        ret = grass.run_command("r.series", flags=flag, file=filename,
-                                output=output, overwrite=grass.overwrite(),
-                                method=method)
+        try:
+            grass.run_command("r.series", flags=flag, file=filename,
+                              output=output, overwrite=grass.overwrite(),
+                              method=method)
+        except CalledModuleError:
+            grass.fatal(_("%s failed. Check above error messages.") % 'r.series')
 
-        if ret == 0 and not add_time:
+        if not add_time:
             # Create the time range for the output map
             if output.find("@") >= 0:
                 id = output

Modified: grass/branches/releasebranch_7_0/temporal/t.rast.to.rast3/t.rast.to.rast3.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/temporal/t.rast.to.rast3/t.rast.to.rast3.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -31,6 +31,7 @@
 import grass.script as grass
 import grass.temporal as tgis
 from datetime import datetime
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -111,9 +112,9 @@
         bottom = start
 
     top = float(bottom + granularity * float(num_maps))
-    ret = grass.run_command("g.region", t=top, b=bottom, tbres=granularity)
-
-    if ret != 0:
+    try:
+        grass.run_command("g.region", t=top, b=bottom, tbres=granularity)
+    except CalledModuleError:
         grass.fatal(_("Unable to set 3d region"))
 
     # Create a NULL map to fill the gaps
@@ -142,10 +143,10 @@
 
             count += 1
 
-        ret = grass.run_command("r.to.rast3", input=map_names,
-                                output=output, overwrite=grass.overwrite())
-
-        if ret != 0:
+        try:
+            grass.run_command("r.to.rast3", input=map_names,
+                              output=output, overwrite=grass.overwrite())
+        except CalledModuleError:
             grass.fatal(_("Unable to create 3D raster map <%s>" % output))
 
     grass.run_command("g.remove", type='rast', name=null_map, flags='f')
@@ -154,9 +155,12 @@
     descr = _("This space time voxel cube was created with t.rast.to.rast3")
 
     # Set the unit
-    ret = grass.run_command("r3.support", map=output, vunit=unit,
-                            title=title, description=descr,
-                            overwrite=grass.overwrite())
+    try:
+        grass.run_command("r3.support", map=output, vunit=unit,
+                          title=title, description=descr,
+                          overwrite=grass.overwrite())
+    except CalledModuleError:
+        grass.warning(_("%s failed to set units.") % 'r3.support')
 
     # Register the space time voxel cube in the temporal GIS
     if output.find("@") >= 0:

Modified: grass/branches/releasebranch_7_0/temporal/t.vect.observe.strds/t.vect.observe.strds.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/temporal/t.vect.observe.strds/t.vect.observe.strds.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -53,6 +53,7 @@
 import grass.script as grass
 import grass.temporal as tgis
 import grass.script.raster as raster
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -191,10 +192,11 @@
     vectmap = vector_output
 
     # We create a new vector map using the categories of the original map
-    ret = grass.run_command("v.category", input=input, layer=layers,
-                            output=vectmap, option="transfer",
-                            overwrite=overwrite)
-    if ret != 0:
+    try:
+        grass.run_command("v.category", input=input, layer=layers,
+                          output=vectmap, option="transfer",
+                          overwrite=overwrite)
+    except CalledModuleError:
         grass.fatal(_("Unable to create new layers for vector map <%s>")
                     % (vectmap))
 
@@ -240,29 +242,32 @@
 
         # Try to add a column
         if vector_db and count in vector_db and vector_db[count]["table"]:
-            ret = grass.run_command("v.db.addcolumn", map=vectmap,
-                                    layer=count, column=columns_string,
-                                    overwrite=overwrite)
-            if ret != 0:
+            try:
+                grass.run_command("v.db.addcolumn", map=vectmap,
+                                  layer=count, column=columns_string,
+                                  overwrite=overwrite)
+            except CalledModuleError:
                 dbif.close()
                 grass.fatal(_("Unable to add column %s to vector map <%s> "
                               "with layer %i") % (columns_string, vectmap, count))
         else:
             # Try to add a new table
             grass.message("Add table to layer %i" % (count))
-            ret = grass.run_command("v.db.addtable", map=vectmap, layer=count,
-                                    columns=columns_string, overwrite=overwrite)
-            if ret != 0:
+            try:
+                grass.run_command("v.db.addtable", map=vectmap, layer=count,
+                                  columns=columns_string, overwrite=overwrite)
+            except CalledModuleError:
                 dbif.close()
                 grass.fatal(_("Unable to add table to vector map "
                               "<%s> with layer %i") % (vectmap, count))
 
         # Call v.what.rast for each raster map
         for name, column in zip(raster_names, column_names):
-            ret = grass.run_command("v.what.rast", map=vectmap,
-                                    layer=count, raster=name,
-                                    column=column, where=where)
-            if ret != 0:
+            try:
+                grass.run_command("v.what.rast", map=vectmap,
+                                  layer=count, raster=name,
+                                  column=column, where=where)
+            except CalledModuleError:
                 dbif.close()
                 grass.fatal(_("Unable to run v.what.rast for vector map <%s> "
                             "with layer %i and raster map <%s>") % \

Modified: grass/branches/releasebranch_7_0/temporal/t.vect.what.strds/t.vect.what.strds.py
===================================================================
--- grass/branches/releasebranch_7_0/temporal/t.vect.what.strds/t.vect.what.strds.py	2014-11-18 00:21:48 UTC (rev 62785)
+++ grass/branches/releasebranch_7_0/temporal/t.vect.what.strds/t.vect.what.strds.py	2014-11-18 02:33:39 UTC (rev 62786)
@@ -60,6 +60,7 @@
 import grass.script as grass
 import grass.temporal as tgis
 import grass.script.raster as raster
+from grass.exceptions import CalledModuleError
 
 ############################################################################
 
@@ -153,42 +154,42 @@
                 if rasterinfo["datatype"] == "CELL":
                     coltype = "INT"
 
-                if layer:
-                    ret = grass.run_command("v.db.addcolumn",
-                                            map=vectmap, layer=layer,
-                                            column="%s %s" % (col_name, coltype),
-                                            overwrite=grass.overwrite())
-                else:
-                    ret = grass.run_command("v.db.addcolumn", map=vectmap,
-                                            column="%s %s" % (col_name, coltype),
-                                            overwrite=grass.overwrite())
-
-                if ret != 0:
+                try:
+                    if layer:
+                        grass.run_command("v.db.addcolumn",
+                                          map=vectmap, layer=layer,
+                                          column="%s %s" % (col_name, coltype),
+                                          overwrite=grass.overwrite())
+                    else:
+                        grass.run_command("v.db.addcolumn", map=vectmap,
+                                          column="%s %s" % (col_name, coltype),
+                                          overwrite=grass.overwrite())
+                except CalledModuleError:
                     dbif.close()
                     grass.fatal(_("Unable to add column %s to vector map <%s>")
                                 % (col_name, vectmap))
 
                 # Call v.what.rast
-                if layer:
-                    ret = grass.run_command("v.what.rast", map=vectmap,
-                                            layer=layer, raster=rastermap,
-                                            column=col_name, where=where)
-                else:
-                    ret = grass.run_command("v.what.rast", map=vectmap,
-                                            raster=rastermap, column=col_name,
-                                            where=where)
-                if ret != 0:
+                try:
+                    if layer:
+                        grass.run_command("v.what.rast", map=vectmap,
+                                          layer=layer, raster=rastermap,
+                                          column=col_name, where=where)
+                    else:
+                        grass.run_command("v.what.rast", map=vectmap,
+                                          raster=rastermap, column=col_name,
+                                          where=where)
+                except CalledModuleError:
                     dbif.close()
                     grass.fatal(_("Unable to run v.what.rast for vector map "
                                   "<%s> and raster map <%s>") % (vectmap,
                                                                  rastermap))
 
                 if aggreagated_map_name:
-                    ret = grass.run_command("g.remove",
-                                            flags='f',
-                                            type='rast',
-                                            name=aggreagated_map_name)
-                    if ret != 0:
+                    try:
+                        grass.run_command("g.remove", flags='f', type='rast',
+                                          name=aggreagated_map_name)
+                    except CalledModuleError:
                         dbif.close()
                         grass.fatal(_("Unable to remove raster map <%s>")
                                     % (aggreagated_map_name))



More information about the grass-commit mailing list