Skip to content

Commit

Permalink
Remove sys.exit() calls.
Browse files Browse the repository at this point in the history
Click can do this for us. If we raise click.Abort(), we get the
proper return value of 1.

Closes #350.
  • Loading branch information
Sean Gillies committed May 27, 2015
1 parent e4636f0 commit 20bd613
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 28 deletions.
5 changes: 2 additions & 3 deletions rasterio/rio/bands.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def stack(ctx, files, output, driver, bidx, photometric):
dst.write(data, range(dst_idx, dst_idx+len(index)))
dst_idx += len(index)

sys.exit(0)
except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()
5 changes: 2 additions & 3 deletions rasterio/rio/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,14 @@ def calc(ctx, command, files, output, name, dtype, masked):
with rasterio.open(output, 'w', **kwargs) as dst:
dst.write(results)

sys.exit(0)
except snuggs.ExpressionError as err:
click.echo("Expression Error:")
click.echo(' %s' % err.text)
click.echo(' ' + ' ' * err.offset + "^")
click.echo(err)
sys.exit(1)
raise click.Abort()
except Exception as err:
t, v, tb = sys.exc_info()
for line in traceback.format_exception_only(t, v):
click.echo(line, nl=False)
sys.exit(1)
raise click.Abort()
5 changes: 2 additions & 3 deletions rasterio/rio/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,9 @@ def __call__(self):
stdout, Collection(), sequence=sequence,
geojson_type=geojson_type, use_rs=use_rs,
**dump_kwds)
sys.exit(0)
except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()


# Rasterize command.
Expand Down
7 changes: 3 additions & 4 deletions rasterio/rio/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,8 @@ def info(ctx, input, aspect, indent, namespace, meta_member, verbose, bidx,
else:
click.echo(json.dumps(info, indent=indent))
elif aspect == 'tags':
click.echo(json.dumps(src.tags(ns=namespace),
click.echo(json.dumps(src.tags(ns=namespace),
indent=indent))
sys.exit(0)
except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()
5 changes: 2 additions & 3 deletions rasterio/rio/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,6 @@ def merge(ctx, files, output, driver, bounds, res, nodata):
dst.write(dest)
dst.close()

sys.exit(0)
except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()
16 changes: 7 additions & 9 deletions rasterio/rio/rio.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ def insp(ctx, input, mode):
rasterio.__version__,
'.'.join(map(str, sys.version_info[:3]))),
src)
sys.exit(0)
except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()


# Bounds command.
Expand Down Expand Up @@ -149,10 +148,10 @@ def __call__(self):
stdout, col, sequence=sequence,
geojson_type=geojson_type, use_rs=use_rs,
**dump_kwds)
sys.exit(0)

except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()


# Transform command.
Expand Down Expand Up @@ -199,7 +198,6 @@ def transform(ctx, input, src_crs, dst_crs, precision):
result[1::2] = ys
print(json.dumps(result))

sys.exit(0)
except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()
6 changes: 3 additions & 3 deletions rasterio/rio/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def sample(ctx, files, bidx):
(json.loads(line) for line in points),
indexes=indexes):
click.echo(json.dumps(vals.tolist()))
sys.exit(0)

except Exception:
logger.exception("Failed. Exception caught")
sys.exit(1)
logger.exception("Exception caught during processing")
raise click.Abort()

0 comments on commit 20bd613

Please sign in to comment.