Skip to content

Commit

Permalink
Merge pull request #175 from DigitalSlideArchive/171-skip-rename
Browse files Browse the repository at this point in the history
Add flag to skip renaming files
  • Loading branch information
naglepuff authored Jan 3, 2024
2 parents 986c1d9 + 6196183 commit 211da76
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
13 changes: 11 additions & 2 deletions imagedephi/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,21 @@ def imagedephi(
help="Path where output directory will be created.",
type=click.Path(exists=True, file_okay=False, readable=True, writable=True, path_type=Path),
)
@click.option("--rename/--skip-rename", default=True)
@click.pass_obj
def run(obj: ImagedephiContext, input_path: Path, output_dir: Path, verbose, quiet, log_file):
def run(
obj: ImagedephiContext,
input_path: Path,
output_dir: Path,
rename: bool,
verbose,
quiet,
log_file,
):
"""Perform the redaction of images."""
if verbose or quiet or log_file:
set_logging_config(verbose, quiet, log_file)
redact_images(input_path, output_dir, obj.override_rule_set)
redact_images(input_path, output_dir, obj.override_rule_set, rename)


@imagedephi.command
Expand Down
17 changes: 11 additions & 6 deletions imagedephi/redact/redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def redact_images(
input_path: Path,
output_dir: Path,
override_rules: Ruleset | None = None,
rename: bool = True,
overwrite: bool = False,
) -> None:
base_rules = get_base_rules()
Expand Down Expand Up @@ -96,12 +97,16 @@ def redact_images(
redaction_plan.report_missing_rules()
else:
redaction_plan.execute_plan()
output_path = _get_output_path(
image_file,
redact_dir,
output_file_name_base,
output_file_counter,
output_file_max,
output_path = (
_get_output_path(
image_file,
redact_dir,
output_file_name_base,
output_file_counter,
output_file_max,
)
if rename
else redact_dir / image_file.name
)
redaction_plan.save(output_path, overwrite)
if output_file_counter == output_file_max:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,23 @@ def test_e2e_help(cli_runner: CliRunner, help_flag: str) -> None:

assert result.exit_code == 0
assert "Usage: imagedephi" in result.output


@freeze_time("2023-05-12 12:12:53")
@pytest.mark.timeout(5)
@pytest.mark.parametrize("rename", [True, False])
def test_e2e_rename_flag(cli_runner, data_dir: Path, tmp_path: Path, rename: bool):
rename_flag = "--rename" if rename else "--skip-rename"
result = cli_runner.invoke(
main.imagedephi,
["run", str(data_dir / "input" / "tiff"), "--output-dir", str(tmp_path), rename_flag],
)

assert result.exit_code == 0

output_file_name = (
tmp_path / "Redacted_2023-05-12_12-12-53" / "study_slide_1.tif"
if rename
else tmp_path / "Redacted_2023-05-12_12-12-53" / "test_image.tif"
)
assert output_file_name.exists()

0 comments on commit 211da76

Please sign in to comment.