Skip to content

Commit

Permalink
Merge pull request #218 from DigitalSlideArchive/216-cli-progress-bar
Browse files Browse the repository at this point in the history
Use tqdm for progress bar
  • Loading branch information
naglepuff authored May 20, 2024
2 parents e9863e1 + 5cc1805 commit 6a7075e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
15 changes: 6 additions & 9 deletions imagedephi/redact/redact.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from collections.abc import Generator
import datetime
import importlib.resources
from io import StringIO
from pathlib import Path

import click
import tifftools
import tifftools.constants
from tqdm import tqdm
from tqdm.contrib.logging import logging_redirect_tqdm
import yaml

from imagedephi.rules import Ruleset
Expand Down Expand Up @@ -88,13 +88,9 @@ def redact_images(
output_file_counter = 1
output_file_max = len(images_to_redact)
redact_dir = create_redact_dir(output_dir)
show_redaction_plan(input_path)

file = StringIO()
with click.progressbar(
images_to_redact, label="Redacting Images", show_pos=True, file=file, show_percent=True
) as bar:
for image_file in bar:
with logging_redirect_tqdm(loggers=[logger]):
for image_file in tqdm(images_to_redact, desc="Redacting images", position=0, leave=True):
push_progress(output_file_counter, output_file_max)
try:
redaction_plan = build_redaction_plan(image_file, base_rules, override_rules)
Expand All @@ -106,6 +102,7 @@ def redact_images(
logger.info(f"Redaction could not be performed for {image_file.name}.")
redaction_plan.report_missing_rules()
else:
redaction_plan.report_plan()
redaction_plan.execute_plan()
output_parent_dir = redact_dir
if recursive:
Expand All @@ -126,7 +123,7 @@ def redact_images(
)
redaction_plan.save(output_path, overwrite)
if output_file_counter == output_file_max:
click.echo("Redactions completed")
logger.info("Redactions completed")
output_file_counter += 1


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"pyyaml",
"Pillow",
"pydicom",
"tqdm",
"wsidicom",
"websockets",
]
Expand Down

0 comments on commit 6a7075e

Please sign in to comment.