Skip to content

Commit

Permalink
-o no longer implicitly overwrites
Browse files Browse the repository at this point in the history
Resolves #751
  • Loading branch information
Sean Gillies committed Aug 22, 2016
1 parent e47c3fb commit 81ab4d1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
1 change: 0 additions & 1 deletion rasterio/rio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ def resolve_inout(input=None, output=None, files=None, force_overwrite=False):
:param:`force_overwrite` is `True`.
"""
resolved_output = output or (files[-1] if files else None)
force_overwrite = output is not None or force_overwrite
if not force_overwrite and resolved_output and os.path.exists(
resolved_output):
raise FileOverwriteError(
Expand Down
7 changes: 3 additions & 4 deletions rasterio/rio/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ def file_in_handler(ctx, param, value):
except ValueError as exc:
raise click.BadParameter(str(exc))
path_to_check = archive or path
if not scheme in ['http', 'https', 's3'] and not os.path.exists(path_to_check):
if (scheme not in ['http', 'https', 's3'] and not
os.path.exists(path_to_check)):
raise click.BadParameter(
"Input file {0} does not exist".format(path_to_check))
if archive and scheme:
Expand Down Expand Up @@ -201,9 +202,7 @@ def nodata_handler(ctx, param, value):
'-o', '--output',
default=None,
type=click.Path(resolve_path=True),
help="Path to output file (optional alternative to a positional arg). "
"Existing files will be overwritten (`--force-overwrite` is "
"implied).")
help="Path to output file (optional alternative to a positional arg).")

resolution_opt = click.option(
'-r', '--res',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rio_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def test_rasterize_existing_output(tmpdir, runner, basic_feature):
'rasterize', output,
'--dimensions', DEFAULT_SHAPE[0], DEFAULT_SHAPE[1],
'--bounds', 0, 10, 10, 0],
input=json.dumps(basic_feature))
input=json.dumps(basic_feature), catch_exceptions=False)

assert result.exit_code == 0
assert os.path.exists(output)
Expand All @@ -584,7 +584,7 @@ def test_rasterize_existing_output(tmpdir, runner, basic_feature):

result = runner.invoke(
main_group, [
'rasterize', '-o', output, '--dimensions', DEFAULT_SHAPE[0],
'rasterize', '--force-overwrite', '-o', output, '--dimensions', DEFAULT_SHAPE[0],
DEFAULT_SHAPE[1]],
input=json.dumps(basic_feature))

Expand Down
6 changes: 3 additions & 3 deletions tests/test_rio_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ def test_force_overwrite(tmpdir):


def test_implicit_overwrite(tmpdir):
"""Implicit overwrite of existing file succeeds."""
"""Implicit overwrite of existing file fails."""
foo_tif = tmpdir.join('foo.tif')
foo_tif.write("content")
output, inputs = helpers.resolve_inout(output=str(foo_tif))
assert output == str(foo_tif)
with pytest.raises(FileOverwriteError):
helpers.resolve_inout(output=str(foo_tif))


def test_to_lower():
Expand Down

0 comments on commit 81ab4d1

Please sign in to comment.