Skip to content

Commit

Permalink
Print filename if stripping contents (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefmolin authored Jun 18, 2024
1 parent 033794f commit a83ab06
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/exif_stripper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ def process_image(filename: str | os.PathLike) -> bool:
try:
# remove EXIF data
with Image.open(filename) as im:
exif = im.getexif()
if exif:
if exif := im.getexif():
exif.clear()
im.save(filename)
has_changed = True
Expand All @@ -45,11 +44,13 @@ def process_image(filename: str | os.PathLike) -> bool:
from xattr import xattr

xattr_obj = xattr(filename)
extended_attributes = xattr_obj.list()
if extended_attributes:
if xattr_obj.list():
xattr_obj.clear()
has_changed = True

if has_changed:
print(f'Stripped metadata from {filename}')

return has_changed


Expand Down
4 changes: 3 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def test_process_image_file_issues(tmp_path, exists):
assert not has_changed


def test_main(tmp_path, image_with_metadata):
def test_main(tmp_path, image_with_metadata, capsys):
"""Test that cli.main() returns the number of files altered."""
file_without_metadata = tmp_path / 'clean.png'
file_without_metadata.touch()
Expand All @@ -101,6 +101,8 @@ def test_main(tmp_path, image_with_metadata):

assert files_changed == 1

assert capsys.readouterr().out.strip().endswith(str(image_with_metadata))


def test_cli_version(capsys):
"""Confirm that --version works."""
Expand Down

0 comments on commit a83ab06

Please sign in to comment.