[GRASS-SVN] r62790 - in grass-addons/grass7: general/g.cloud general/g.proj.all raster/r.lake.series raster/r.lfp raster/r.mwprecip raster/r.soillossbare vector/v.area.weigh vector/v.build.pg vector/v.colors2 vector/v.external.all vector/v.in.geopaparazzi vector/v.in.wfs2 vector/v.lfp vector/v.median vector/v.surf.icw vector/v.what.strds
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 17 19:14:20 PST 2014
Author: wenzeslaus
Date: 2014-11-17 19:14:20 -0800 (Mon, 17 Nov 2014)
New Revision: 62790
Modified:
grass-addons/grass7/general/g.cloud/cloud_unpack.py
grass-addons/grass7/general/g.proj.all/g.proj.all.py
grass-addons/grass7/raster/r.lake.series/r.lake.series.py
grass-addons/grass7/raster/r.lfp/r.lfp.py
grass-addons/grass7/raster/r.mwprecip/r.mwprecip.py
grass-addons/grass7/raster/r.soillossbare/r.soillossbare.py
grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py
grass-addons/grass7/vector/v.build.pg/v.build.pg.py
grass-addons/grass7/vector/v.colors2/v.colors2.py
grass-addons/grass7/vector/v.external.all/v.external.all.py
grass-addons/grass7/vector/v.in.geopaparazzi/v.in.geopaparazzi.py
grass-addons/grass7/vector/v.in.wfs2/wfs_base.py
grass-addons/grass7/vector/v.lfp/v.lfp.py
grass-addons/grass7/vector/v.median/v.median.py
grass-addons/grass7/vector/v.surf.icw/v.surf.icw.py
grass-addons/grass7/vector/v.what.strds/v.what.strds.py
Log:
use new API for run_command and others: do not check return code, catch the exception
* change done in r62566 for trunk and in r62786 for release branch 70
* related ticket #2326
* done for r.skyview in r62687 by zarch
Modified: grass-addons/grass7/general/g.cloud/cloud_unpack.py
===================================================================
--- grass-addons/grass7/general/g.cloud/cloud_unpack.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/general/g.cloud/cloud_unpack.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -16,6 +16,7 @@
import glob, os, sys, tarfile, logging
import cloud_which as which
+from grass.exceptions import CalledModuleError
# the home of the user
homeServer = os.getcwd()
@@ -77,8 +78,9 @@
f.write("Error unpacking rastertarpack")
for i in rasters:
logging.debug("Unpacking raster map <%s>" % os.path.join(homeServer,i))
- ret = grass.run_command('r.unpack',input=os.path.join(homeServer,i))
- if ret != 0:
+ try:
+ grass.run_command('r.unpack',input=os.path.join(homeServer,i))
+ except CalledModuleError:
logging.error("Error unpacking raster map <%s>" % os.path.join(homeServer,i))
#os.remove(os.path.join(homeServer,i)) TO UNCOMMENT WHEN ALL WILL BE OK
@@ -93,7 +95,8 @@
for i in vectors:
logging.debug("Unpacking vector map <%s>" % os.path.join(homeServer,i))
- ret = grass.run_command('v.unpack',input=os.path.join(homeServer,i))
- if ret != 0:
+ try:
+ grass.run_command('v.unpack',input=os.path.join(homeServer,i))
+ except CalledModuleError:
logging.error("Error unpacking raster map <%s>" % os.path.join(homeServer,i))
#os.remove(os.path.join(homeServer,i)) TO UNCOMMENT WHEN ALL WILL BE OK
Modified: grass-addons/grass7/general/g.proj.all/g.proj.all.py
===================================================================
--- grass-addons/grass7/general/g.proj.all/g.proj.all.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/general/g.proj.all/g.proj.all.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -84,6 +84,7 @@
from grass.script.utils import parse_key_val
from grass.script import core as gcore
+from grass.exceptions import CalledModuleError
def main():
@@ -117,8 +118,9 @@
if dbase:
parameters.update(dict(dbase=dbase))
# first run r.proj to see if it works
- returncode = gcore.run_command('r.proj', quiet=True, **parameters)
- if returncode != 0:
+ try:
+ gcore.run_command('r.proj', quiet=True, **parameters)
+ except CalledModuleError:
gcore.fatal(_("Module r.proj failed. Please check the error messages above."))
# run again to get the raster maps
rasters = gcore.read_command('r.proj', **parameters)
@@ -150,8 +152,9 @@
if dbase:
parameters.update(dict(dbase=dbase))
# first run v.proj to see if it works
- returncode = gcore.run_command('v.proj', quiet=True, **parameters)
- if returncode != 0:
+ try:
+ gcore.run_command('v.proj', quiet=True, **parameters)
+ except CalledModuleError:
gcore.fatal(_("Module v.proj failed. Please check the error messages above."))
# run again to get the vector maps
vectors = gcore.read_command('v.proj', **parameters)
Modified: grass-addons/grass7/raster/r.lake.series/r.lake.series.py
===================================================================
--- grass-addons/grass7/raster/r.lake.series/r.lake.series.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/raster/r.lake.series/r.lake.series.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -120,6 +120,7 @@
from grass.script import core as gcore
import grass.temporal as tgis
+from grass.exceptions import CalledModuleError
def format_time(time):
@@ -193,12 +194,13 @@
flags += 'n'
for i, water_level in enumerate(water_levels):
- return_code = gcore.run_command('r.lake', elevation=elevation,
- lake=outputs[i],
- water_level=water_level,
- overwrite=gcore.overwrite(), # TODO: really works? Its seems that hardcoding here False does not prevent overwriting.
- **kwargs)
- if return_code:
+ try:
+ gcore.run_command('r.lake', elevation=elevation,
+ lake=outputs[i],
+ water_level=water_level,
+ overwrite=gcore.overwrite(), # TODO: really works? Its seems that hardcoding here False does not prevent overwriting.
+ **kwargs)
+ except CalledModuleError:
# remove maps created so far, try to remove also i-th map
remove_raster_maps(outputs[:i], quiet=True)
gcore.fatal(_("r.lake command failed. Check above error messages."
Modified: grass-addons/grass7/raster/r.lfp/r.lfp.py
===================================================================
--- grass-addons/grass7/raster/r.lfp/r.lfp.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/raster/r.lfp/r.lfp.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -32,7 +32,9 @@
import sys
import os
import grass.script as grass
+from grass.exceptions import CalledModuleError
+
def main():
input = options["input"]
output = options["output"]
@@ -52,25 +54,33 @@
if p.returncode != 0:
grass.fatal(_("Cannot create outlet vector map"))
- if grass.run_command("v.to.rast", overwrite=True,
- input=outlet, output=outlet, use="cat") != 0:
+ try:
+ grass.run_command("v.to.rast", overwrite=True,
+ input=outlet, output=outlet, use="cat")
+ except CalledModuleError:
grass.fatal(_("Cannot convert outlet vector to raster"))
flds = prefix + "flds"
- if grass.run_command("r.stream.distance", overwrite=True, flags="om",
- stream_rast=outlet, direction=input, method="downstream",
- distance=flds) != 0:
+ try:
+ grass.run_command("r.stream.distance", overwrite=True, flags="om",
+ stream_rast=outlet, direction=input, method="downstream",
+ distance=flds)
+ except CalledModuleError:
grass.fatal(_("Cannot create flow length downstream raster map"))
flus = prefix + "flus"
- if grass.run_command("r.stream.distance", overwrite=True, flags="o",
- stream_rast=outlet, direction=input, method="upstream",
- distance=flus) != 0:
+ try:
+ grass.run_command("r.stream.distance", overwrite=True, flags="o",
+ stream_rast=outlet, direction=input, method="upstream",
+ distance=flus)
+ except CalledModuleError:
grass.fatal(_("Cannot create flow length upstream raster map"))
fldsus = prefix + "fldsus"
- if grass.run_command("r.mapcalc", overwrite=True,
- expression="%s=%s+%s" % (fldsus, flds, flus)) != 0:
+ try:
+ grass.run_command("r.mapcalc", overwrite=True,
+ expression="%s=%s+%s" % (fldsus, flds, flus))
+ except CalledModuleError:
grass.fatal(_("Cannot create flds+flus raster map"))
p = grass.pipe_command("r.info", flags="r", map=fldsus)
@@ -87,8 +97,10 @@
max = float(max) + 1
min = max - 2
- if grass.run_command("r.mapcalc",
- expression="%s=if(%s>=%f, 1, null())" % (output, fldsus, min)) != 0:
+ try:
+ grass.run_command("r.mapcalc",
+ expression="%s=if(%s>=%f, 1, null())" % (output, fldsus, min))
+ except CalledModuleError:
grass.fatal(_("Cannot create longest flow path raster map"))
grass.run_command("g.remove", flags="f",
Modified: grass-addons/grass7/raster/r.mwprecip/r.mwprecip.py
===================================================================
--- grass-addons/grass7/raster/r.mwprecip/r.mwprecip.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/raster/r.mwprecip/r.mwprecip.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -15,10 +15,11 @@
import re
from collections import defaultdict
from datetime import datetime ,timedelta
-from math import sin, cos, atan2,degrees,radians, tan,sqrt,fabs
+from math import sin, cos, atan2,degrees,radians, tan,sqrt,fabs
try:
- from grass.script import core as grass
+ from grass.script import core as grass
+ from grass.exceptions import CalledModuleError
except ImportError:
sys.exit("Cannot find 'grass' Python module. Python is supported by GRASS from version >= 6.4")
@@ -569,18 +570,29 @@
print_message("Connecting to db-GRASS...")
# Unfortunately we cannot test untill user/password is set
if user or password:
- if grass.run_command('db.login', driver = "pg", database = database, user = user, password = password) != 0:
+ try:
+ grass.run_command('db.login', driver = "pg", database = database,
+ user = user, password = password)
+ except CalledModuleError:
grass.fatal("Cannot login")
# Try to connect
- if grass.run_command('db.select', quiet = True, flags='c', driver= "pg", database=database, sql="select version()" ) != 0:
+ try:
+ grass.run_command('db.select', quiet = True, flags='c',
+ driver= "pg", database=database, sql="select version()" )
+ except CalledModuleError:
if user or password:
print_message( "Deleting login (db.login) ...")
- if grass.run_command('db.login', quiet = True, driver = "pg", database = database, user = "", password = "") != 0:
+ try:
+ grass.run_command('db.login', quiet = True, driver = "pg",
+ database = database, user = "", password = "")
+ except CalledModuleError:
print_message("Cannot delete login.")
grass.fatal("Cannot connect to database.")
- if grass.run_command('db.connect', driver = "pg", database = database) != 0:
+ try:
+ grass.run_command('db.connect', driver = "pg", database = database)
+ except CalledModuleError:
grass.fatal("Cannot connect to database.")
def dbConnPy():
Modified: grass-addons/grass7/raster/r.soillossbare/r.soillossbare.py
===================================================================
--- grass-addons/grass7/raster/r.soillossbare/r.soillossbare.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/raster/r.soillossbare/r.soillossbare.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -144,6 +144,7 @@
import sys
import os
import grass.script as g
+from grass.exceptions import CalledModuleError
class rusle_base(object):
@@ -213,13 +214,14 @@
def removeTempRasters(self):
for tmprast in self.tmp_rast:
g.message('Removing "%s"' %tmprast)
- remove = g.run_command('g.remove',
- flags = 'f',
- type = 'rast',
- name = tmprast,
- quiet = True)
-
- return remove
+ try:
+ g.run_command('g.remove',
+ flags = 'f',
+ type = 'rast',
+ name = tmprast,
+ quiet = True)
+ except CalledModuleError:
+ g.warning(_("Removing temporary raster maps failed"))
def rusle(self):
"""!main method in rusle_base
Modified: grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py
===================================================================
--- grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.area.weigh/v.area.weigh.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -38,6 +38,7 @@
import os
import atexit
import grass.script as grass
+from grass.exceptions import CalledModuleError
def cleanup():
@@ -89,21 +90,28 @@
# strip off mapset for tmp output
vector_basename = vector.split("@")[0]
rastertmp1 = "%s_%s_1" % (vector_basename, tmpname)
- if grass.run_command('v.to.rast', input = vector, output = rastertmp1,
- use = 'cat', quiet = True) != 0:
- grass.fatal(_("An error occurred while converting vector to raster"))
+ try:
+ grass.run_command('v.to.rast', input=vector, output=rastertmp1,
+ use='cat', quiet=True)
+ except CalledModuleError:
+ grass.fatal(_("An error occurred while converting vector to raster"))
# rasterize with column
rastertmp2 = "%s_%s_2" % (vector_basename, tmpname)
- if grass.run_command('v.to.rast', input = vector, output = rastertmp2,
- use = 'attr', layer = layer, attrcolumn = column, quiet = True) != 0:
- grass.fatal(_("An error occurred while converting vector to raster"))
+ try:
+ grass.run_command('v.to.rast', input=vector, output=rastertmp2,
+ use='attr', layer=layer, attrcolumn=column,
+ quiet=True)
+ except CalledModuleError:
+ grass.fatal(_("An error occurred while converting vector to raster"))
# zonal statistics
rastertmp3 = "%s_%s_3" % (vector_basename, tmpname)
- if grass.run_command('r.statistics2', base = rastertmp1, cover = weight,
- method = 'sum', output = rastertmp3, quiet = True) != 0:
- grass.fatal(_("An error occurred while calculating zonal statistics"))
+ try:
+ grass.run_command('r.statistics2', base=rastertmp1, cover=weight,
+ method='sum', output=rastertmp3, quiet=True)
+ except CalledModuleError:
+ grass.fatal(_("An error occurred while calculating zonal statistics"))
# weighted interpolation
exp = "$output = if($sumweight == 0, if(isnull($area_val), null(), 0), double($area_val) * $weight / $sumweight)"
Modified: grass-addons/grass7/vector/v.build.pg/v.build.pg.py
===================================================================
--- grass-addons/grass7/vector/v.build.pg/v.build.pg.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.build.pg/v.build.pg.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -51,7 +51,9 @@
import sys
import grass.script as grass
+from grass.exceptions import CalledModuleError
+
def execute(sql, msg = None, useSelect = True):
if useSelect:
cmd = 'select'
@@ -62,16 +64,15 @@
sys.stdout.write("\n%s\n\n" % sql)
return
- ret = grass.run_command('db.%s' % cmd, sql = sql,
- **pg_conn)
- if ret == 0:
- return
-
- if msg:
- grass.fatal(msg)
- else:
- grass.fatal(_("Unable to build PostGIS topology"))
+ try:
+ grass.run_command('db.%s' % cmd, sql=sql, **pg_conn)
+ except CalledModuleError:
+ if msg:
+ grass.fatal(msg)
+ else:
+ grass.fatal(_("Unable to build PostGIS topology"))
+
def main():
vmap = options['map']
curr_mapset = grass.gisenv()['MAPSET']
Modified: grass-addons/grass7/vector/v.colors2/v.colors2.py
===================================================================
--- grass-addons/grass7/vector/v.colors2/v.colors2.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.colors2/v.colors2.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -85,7 +85,9 @@
import atexit
import string
import grass.script as grass
+from grass.exceptions import CalledModuleError
+
def cleanup():
if tmp:
grass.try_remove(tmp)
@@ -150,9 +152,11 @@
table = grass.vector_db(map)[int(layer)]['table']
if rgb_column not in cols:
# RGB Column not found, create it
- grass.message(_("Creating column <%s>...") % rgb_column)
- if 0 != grass.run_command('v.db.addcolumn', map = map, layer = layer, column = "%s varchar(11)" % rgb_column):
- grass.fatal(_("Creating color column"))
+ grass.message(_("Creating column <%s>...") % rgb_column)
+ try:
+ grass.run_command('v.db.addcolumn', map = map, layer = layer, column = "%s varchar(11)" % rgb_column)
+ except CalledModuleError:
+ grass.fatal(_("Creating color column"))
else:
column_type = cols[rgb_column]['type']
if column_type not in ["CHARACTER", "TEXT"]:
@@ -244,8 +248,10 @@
# apply SQL commands to update the table with values
grass.message(_("Writing %s colors...") % found)
- if 0 != grass.run_command('db.execute', input = tmp_vcol):
- grass.fatal(_("Processing SQL transaction"))
+ try:
+ grass.run_command('db.execute', input = tmp_vcol)
+ except CalledModuleError:
+ grass.fatal(_("Processing SQL transaction"))
if flags['s']:
vcolors = "vcolors_%d" % pid
Modified: grass-addons/grass7/vector/v.external.all/v.external.all.py
===================================================================
--- grass-addons/grass7/vector/v.external.all/v.external.all.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.external.all/v.external.all.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -33,7 +33,9 @@
import sys
from grass.script import core as grass
+from grass.exceptions import CalledModuleError
+
def list_layers(dsn):
ret = grass.read_command('v.external',
flags = 'l',
@@ -50,8 +52,10 @@
oname = layer.replace('.', '_')
grass.message(_("%s\nCreating link for OGR layer <%s> as <%s>...\n%s") % \
('-' * 80, layer, oname, '-' * 80))
- if 0 != grass.run_command('v.external',
- dsn = dsn, layer = layer, output = oname):
+ try:
+ grass.run_command('v.external',
+ dsn = dsn, layer = layer, output = oname)
+ except CalledModuleError:
grass.warning(_("Unable to create link for OGR layer <%s>") % layer)
def main():
Modified: grass-addons/grass7/vector/v.in.geopaparazzi/v.in.geopaparazzi.py
===================================================================
--- grass-addons/grass7/vector/v.in.geopaparazzi/v.in.geopaparazzi.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.in.geopaparazzi/v.in.geopaparazzi.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -55,6 +55,7 @@
from grass.script.utils import basename
from grass.script import core as grass
from grass.script import db as grassdb
+from grass.exceptions import CalledModuleError
from types import DictType, ListType
import json
@@ -137,9 +138,11 @@
points = returnAll(c, psel)
wpoi = '\n'.join(['|'.join([str(col) for col in row]) for row in points])
# import points using v.in.ascii
- if grass.write_command('v.in.ascii', flags='t%s' % z, input='-', z=zcol,
- output=vname, stdin=wpoi, overwrite=owrite,
- quiet=True) != 0:
+ try:
+ grass.write_command('v.in.ascii', flags='t%s' % z, input='-', z=zcol,
+ output=vname, stdin=wpoi, overwrite=owrite,
+ quiet=True)
+ except CalledModuleError:
grass.fatal(_("Error importing %s" % vname))
return points
@@ -326,9 +329,11 @@
else:
tracks += 'NaN|Nan\n'
# import lines
- if grass.write_command('v.in.lines', flags=d3, input='-',
- out=tracksname, stdin=tracks,
- overwrite=owrite, quiet=True) != 0:
+ try:
+ grass.write_command('v.in.lines', flags=d3, input='-',
+ out=tracksname, stdin=tracks,
+ overwrite=owrite, quiet=True)
+ except CalledModuleError:
grass.fatal(_("Error importing %s" % tracksname))
# create table for line
sql='CREATE TABLE %s (cat int, startts text, ' % tracksname
Modified: grass-addons/grass7/vector/v.in.wfs2/wfs_base.py
===================================================================
--- grass-addons/grass7/vector/v.in.wfs2/wfs_base.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.in.wfs2/wfs_base.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -4,7 +4,9 @@
from urllib2 import urlopen, HTTPError, URLError
import grass.script as grass
+from grass.exceptions import CalledModuleError
+
class WFSBase:
def __init__(self):
# these variables are information for destructor
@@ -231,11 +233,13 @@
grass.message(_("Importing vector map into GRASS..."))
# importing temp_map into GRASS
- if grass.run_command('v.in.ogr',
- quiet = True,
- overwrite = True,
- dsn = temp_warpmap,
- output = self.o_output) != 0:
+ try:
+ grass.run_command('v.in.ogr',
+ quiet = True,
+ overwrite = True,
+ dsn = temp_warpmap,
+ output = self.o_output)
+ except CalledModuleError:
grass.fatal(_('%s failed') % 'v.in.ogr')
grass.try_rmdir(temp_warpmap)
Modified: grass-addons/grass7/vector/v.lfp/v.lfp.py
===================================================================
--- grass-addons/grass7/vector/v.lfp/v.lfp.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.lfp/v.lfp.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -34,7 +34,9 @@
import os
import math
import grass.script as grass
+from grass.exceptions import CalledModuleError
+
def main():
input = options["input"]
output = options["output"]
@@ -56,17 +58,22 @@
res = float(res)
danglelen = math.ceil(math.sqrt(2)*res)
- if grass.run_command("r.to.vect",
- input=input, output=output, type="line") != 0:
+ try:
+ grass.run_command("r.to.vect", input=input, output=output, type="line")
+ except CalledModuleError:
grass.fatal(_("Cannot convert the input raster map to a vector map"))
- if grass.run_command("v.edit", map=output, tool="delete",
- query="dangle", threshold="0,0,-%f" % danglelen) != 0:
+ try:
+ grass.run_command("v.edit", map=output, tool="delete",
+ query="dangle", threshold="0,0,-%f" % danglelen)
+ except CalledModuleError:
grass.fatal(_("Cannot delete dangles from the output vector map"))
success = False
for i in range(0, 100):
- if grass.run_command("v.edit", map=output, tool="merge", where="") != 0:
+ try:
+ grass.run_command("v.edit", map=output, tool="merge", where="")
+ except CalledModuleError:
grass.fatal(_("Cannot merge features in the output vector map"))
p = grass.pipe_command("v.info", flags="t", map=output)
@@ -104,8 +111,10 @@
if firstcat == "":
grass.fatal(_("Cannot further simplify the longest flow path"))
- if grass.run_command("v.edit", map=output, tool="delete",
- cats=firstcat) != 0:
+ try:
+ grass.run_command("v.edit", map=output, tool="delete",
+ cats=firstcat)
+ except CalledModuleError:
grass.fatal(_("Cannot delete short segments from the output vector map"))
if success == False:
@@ -129,8 +138,10 @@
mincat = int(mincat)
maxcat = int(maxcat)
- if grass.run_command("v.edit", map=output, tool="catdel",
- cats="%d-%d" % (mincat+1, maxcat), where="") != 0:
+ try:
+ grass.run_command("v.edit", map=output, tool="catdel",
+ cats="%d-%d" % (mincat+1, maxcat), where="")
+ except CalledModuleError:
grass.fatal(_("Cannot delete categories from the output vector map"))
if coords != "":
@@ -157,10 +168,12 @@
if startx >= outx - res * 0.5 and startx <= outx + res * 0.5 and \
starty >= outy - res * 0.5 and starty <= outy + res * 0.5:
- if grass.run_command("v.edit", map=output, tool="flip",
- where="") != 0:
+ try:
+ grass.run_command("v.edit", map=output, tool="flip", where="")
+ except CalledModuleError:
grass.fatal(_("Cannot flip the longest flow path"))
+
if __name__ == "__main__":
options, flags = grass.parser()
sys.exit(main())
Modified: grass-addons/grass7/vector/v.median/v.median.py
===================================================================
--- grass-addons/grass7/vector/v.median/v.median.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.median/v.median.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -37,8 +37,10 @@
import sys, os
from grass.script.utils import try_remove
from grass.script import core as grass
+from grass.exceptions import CalledModuleError
from numpy import transpose, genfromtxt, median
+
def point_med(filetmp):
# function to return the median point, x and y
point_list = transpose(genfromtxt(filetmp, delimiter='|',usecols=(0,1)))
@@ -52,8 +54,11 @@
grass.fatal(_("Vector map <%s> not found") % infile)
# create tempfile and write ascii file of input
temp_in = grass.tempfile()
- inascii = grass.run_command('v.out.ascii', overwrite = True, input=gfile['name'],
- output = temp_in)
+ try:
+ grass.run_command('v.out.ascii', overwrite = True, input=gfile['name'],
+ output = temp_in)
+ except CalledModuleError:
+ grass.fatal(_("Failed to export vector in a temporary file"))
# x and y of median point
medx, medy = point_med(temp_in)
try_remove(temp_in)
@@ -80,11 +85,11 @@
# output file exists and overwrite
elif goutfile['file'] and overwrite == '1':
grass.warning(_("Vector map <%s> already exists and will be overwritten") % map_name)
- outascii = grass.run_command('v.in.ascii', overwrite = True, input=temp_out,
+ grass.run_command('v.in.ascii', overwrite = True, input=temp_out,
output = map_name)
# output file not exists
else:
- outascii = grass.run_command('v.in.ascii', input=temp_out, output = map_name)
+ grass.run_command('v.in.ascii', input=temp_out, output = map_name)
try_remove(temp_out)
if __name__ == "__main__":
Modified: grass-addons/grass7/vector/v.surf.icw/v.surf.icw.py
===================================================================
--- grass-addons/grass7/vector/v.surf.icw/v.surf.icw.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.surf.icw/v.surf.icw.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -124,6 +124,7 @@
import os
import atexit
import grass.script as grass
+from grass.exceptions import CalledModuleError
def cleanup():
@@ -382,10 +383,11 @@
#grass.run_command('g.list', type = 'rast', mapset = '.')
sum_of_1by_cost_sqs = tmp_base + 'sum_of_1by_cost_sqs'
- ret = grass.run_command('r.series', method = 'sum', input = input_maps,
- output = sum_of_1by_cost_sqs)
- if ret is not 0:
- grass.fatal(_('Problem running %s') % 'r.series')
+ try:
+ grass.run_command('r.series', method='sum', input=input_maps,
+ output=sum_of_1by_cost_sqs)
+ except CalledModuleError:
+ grass.fatal(_('Problem running %s') % 'r.series')
if post_mask:
grass.message(_("Removing post_mask <%s>"), post_mask)
@@ -468,10 +470,11 @@
for i in range(2, n+1):
input_maps += ',%spartial.%05d' % (tmp_base, i)
- ret = grass.run_command('r.series', method = 'sum', input = input_maps,
- output = output)
- if ret is not 0:
- grass.fatal(_('Problem running %s') % 'r.series')
+ try:
+ grass.run_command('r.series', method='sum', input=input_maps,
+ output=output)
+ except CalledModuleError:
+ grass.fatal(_('Problem running %s') % 'r.series')
#TODO: r.patch in v.to.rast of values at exact seed site locations. currently set to null
Modified: grass-addons/grass7/vector/v.what.strds/v.what.strds.py
===================================================================
--- grass-addons/grass7/vector/v.what.strds/v.what.strds.py 2014-11-18 02:58:08 UTC (rev 62789)
+++ grass-addons/grass7/vector/v.what.strds/v.what.strds.py 2014-11-18 03:14:20 UTC (rev 62790)
@@ -46,6 +46,7 @@
from grass.pygrass.utils import copy as gcopy
from grass.pygrass.messages import Messenger
from grass.pygrass.vector import Vector
+from grass.exceptions import CalledModuleError
############################################################################
@@ -182,8 +183,9 @@
grass.fatal(_("It is not possible to open the new map %s" % output))
if len(pymap.dblinks) == 0:
- ret = grass.run_command("v.db.addtable", map=output)
- if ret != 0:
+ try:
+ grass.run_command("v.db.addtable", map=output)
+ except CalledModuleError:
dbif.close()
grass.fatal(_("Impossible add table to vector %s" % output))
for sample in samples:
@@ -201,16 +203,18 @@
column_name = "%s_%s" % (sample.strds_name, day)
column_string = "%s %s" % (column_name, coltype)
column_string.replace('.', '_')
- ret = grass.run_command("v.db.addcolumn", map=output,
- column=column_string, overwrite=overwrite)
- if ret != 0:
+ try:
+ grass.run_command("v.db.addcolumn", map=output,
+ column=column_string, overwrite=overwrite)
+ except CalledModuleError:
dbif.close()
grass.fatal(_("Unable to add column %s to vector map <%s> ") \
% (column_string, output))
- ret = grass.run_command("v.what.rast", map=output, raster=name,
- column=column_name, where=where,
- quiet=quiet)
- if ret != 0:
+ try:
+ grass.run_command("v.what.rast", map=output, raster=name,
+ column=column_name, where=where,
+ quiet=quiet)
+ except CalledModuleError:
dbif.close()
grass.fatal(_("Unable to run v.what.rast for vector map <%s> "
"and raster map <%s>") % \
More information about the grass-commit
mailing list