From a3bede25fcbb5d39c070828ea2b4872d3c3f6792 Mon Sep 17 00:00:00 2001 From: Matthew Perry Date: Tue, 20 Sep 2016 11:31:34 -0400 Subject: [PATCH] rio overview branch logic, --ls opens readonly --- rasterio/rio/overview.py | 16 ++++++++++------ tests/test_rio_overview.py | 8 ++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/rasterio/rio/overview.py b/rasterio/rio/overview.py index 32c5d210..656387bb 100644 --- a/rasterio/rio/overview.py +++ b/rasterio/rio/overview.py @@ -67,9 +67,8 @@ def overview(ctx, input, build, ls, rebuild, resampling): """ with ctx.obj['env']: - with rasterio.open(input, 'r+') as dst: - - if ls: + if ls: + with rasterio.open(input, 'r') as dst: resampling_method = dst.tags( ns='rio_overview').get('resampling') or 'unknown' @@ -77,8 +76,8 @@ def overview(ctx, input, build, ls, rebuild, resampling): for idx in dst.indexes: click.echo(" Band %d: %s (method: '%s')" % ( idx, dst.overviews(idx) or 'None', resampling_method)) - - elif rebuild: + elif rebuild: + with rasterio.open(input, 'r+') as dst: # Build the same overviews for all bands. factors = reduce( operator.or_, @@ -91,8 +90,13 @@ def overview(ctx, input, build, ls, rebuild, resampling): dst.build_overviews( list(factors), Resampling[resampling_method]) - elif build: + elif build: + with rasterio.open(input, 'r+') as dst: dst.build_overviews(build, Resampling[resampling]) # Save the resampling method to a tag. dst.update_tags(ns='rio_overview', resampling=resampling) + + else: + raise click.UsageError( + "Please specify --ls, --rebuild, or --build ...") diff --git a/tests/test_rio_overview.py b/tests/test_rio_overview.py index 60efd731..9cee732f 100644 --- a/tests/test_rio_overview.py +++ b/tests/test_rio_overview.py @@ -66,3 +66,11 @@ def test_rebuild_ls(data): expected = " Band 1: [2, 4, 8] (method: 'cubic')\n Band 2: [2, 4, 8] (method: 'cubic')\n Band 3: [2, 4, 8] (method: 'cubic')\n" assert result.output.endswith(expected) + + +def test_no_args(data): + runner = CliRunner() + inputfile = str(data.join('RGB.byte.tif')) + result = runner.invoke(cli, ['overview', inputfile]) + assert result.exit_code == 2 + assert "Please specify --ls, --rebuild, or --build ..." in result.output