Skip to content

Commit

Permalink
Rename imutils.exif to imutils.metadata
Browse files Browse the repository at this point in the history
Renaming is done as this file handles all metadata related
functionalities and not just exif metadata.
  • Loading branch information
jcjgraf committed Jan 8, 2023
1 parent 4f829cb commit 7a609c7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions vimiv/gui/metadatawidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
from PyQt5.QtWidgets import QLabel, QSizePolicy, QWidget

from vimiv import api, utils
from vimiv.imutils import exif
from vimiv.imutils import metadata
from vimiv.config import styles

_logger = utils.log.module_logger(__name__)


# TODO: conditional fails as this file is imported before plugins are loaded
# if exif.has_get_metadata():
# if metadata.has_get_metadata():
if True:
class MetadataWidget(QLabel):
"""Overlay widget to display image metadata.
Expand Down Expand Up @@ -59,18 +59,18 @@ def __init__(self, parent: QWidget):
self._mainwindow_width = 0
self._path = ""
self._current_set = ""
self._handler: Optional[exif.MetadataHandler] = None
self._handler: Optional[metadata.MetadataHandler] = None

api.signals.new_image_opened.connect(self._on_image_opened)
api.settings.metadata.current_keyset.changed.connect(self._update_text)

self.hide()

@property
def handler(self) -> exif.MetadataHandler:
def handler(self) -> metadata.MetadataHandler:
"""Return the MetadataHandler for the current path."""
if self._handler is None:
self._handler = exif.MetadataHandler(self._path)
self._handler = metadata.MetadataHandler(self._path)
return self._handler

@api.keybindings.register("i", "metadata", mode=api.modes.IMAGE)
Expand Down
2 changes: 1 addition & 1 deletion vimiv/imutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
the appropriate Qt widget.
"""

from vimiv.imutils import exif
from vimiv.imutils import metadata
from vimiv.imutils.edit_handler import EditHandler
from vimiv.imutils.filelist import current, pathlist
from vimiv.imutils.filelist import SignalHandler as _FilelistSignalHandler
Expand Down
8 changes: 4 additions & 4 deletions vimiv/imutils/_file_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def write_pixmap(pixmap, path, original_path):
Args:
pixmap: The QPixmap to write.
path: Path to write the pixmap to.
original_path: Original path of the opened pixmap to retrieve exif information.
original_path: Original path of the opened pixmap to retrieve metadata information.
"""
try:
_can_write(pixmap, path)
Expand Down Expand Up @@ -210,10 +210,10 @@ def _write(pixmap, path, original_path):
handle, filename = tempfile.mkstemp(suffix=ext)
os.close(handle)
pixmap.save(filename)
# Copy exif info from original file to new file
# Copy metadata info from original file to new file
try:
imutils.exif.MetadataHandler(original_path).copy_metadata(filename)
except imutils.exif.UnsupportedMetadataOperation:
imutils.metadata.MetadataHandler(original_path).copy_metadata(filename)
except imutils.metadata.UnsupportedMetadataOperation:
pass
shutil.move(filename, path)
# Check if valid image was created
Expand Down
4 changes: 2 additions & 2 deletions vimiv/imutils/filelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def exif_date_time() -> str:
be used as basis to work with.
"""
try:
return imutils.exif.MetadataHandler(current()).get_date_time()
except imutils.exif.UnsupportedMetadataOperation:
return imutils.metadata.MetadataHandler(current()).get_date_time()
except imutils.metadata.UnsupportedMetadataOperation:
return ""


Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions vimiv/plugins/metadata_piexif.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import piexif

from vimiv.imutils import exif
from vimiv.imutils import metadata
from vimiv.utils import log

_logger = log.module_logger(__name__)
Expand All @@ -45,7 +45,7 @@ def prepare_backend(path: Path) -> Optional[Dict[str, Any]]:
return None


@exif.register(exif.Operations.copy_metadata)
@metadata.register(metadata.Operations.copy_metadata)
def copy_metadata(path: Path, dest: str, reset_orientation: bool = True) -> bool:
"""Copy metadata from current image to dest."""
metadata = prepare_backend(path)
Expand All @@ -58,15 +58,15 @@ def copy_metadata(path: Path, dest: str, reset_orientation: bool = True) -> bool
with contextlib.suppress(KeyError):
metadata["0th"][
piexif.ImageIFD.Orientation
] = exif.ExifOrientation.Normal
] = metadata.ExifOrientation.Normal
exif_bytes = piexif.dump(metadata)
piexif.insert(exif_bytes, dest)
return True
except ValueError:
return False


@exif.register(exif.Operations.get_date_time)
@metadata.register(metadata.Operations.get_date_time)
def get_date_time(path: Path) -> str:
"""Get creation date and time as formatted string."""
metadata = prepare_backend(path)
Expand All @@ -79,9 +79,9 @@ def get_date_time(path: Path) -> str:
return ""


@exif.register(exif.Operations.get_metadata)
@metadata.register(metadata.Operations.get_metadata)
@functools.lru_cache(1)
def get_metadata(path: Path, desired_keys: Sequence[str]) -> exif.MetadataDictT:
def get_metadata(path: Path, desired_keys: Sequence[str]) -> metadata.MetadataDictT:
"""Get value of all desired keys."""
metadata = prepare_backend(path)
out = {}
Expand Down Expand Up @@ -128,7 +128,7 @@ def get_metadata(path: Path, desired_keys: Sequence[str]) -> exif.MetadataDictT:
return out


@exif.register(exif.Operations.get_keys)
@metadata.register(metadata.Operations.get_keys)
@functools.lru_cache(1)
def get_keys(path: Path) -> Iterable[str]:
"""Retrieve the key of all metadata values available in the current image."""
Expand Down
14 changes: 7 additions & 7 deletions vimiv/plugins/metadata_py3exiv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import pyexiv2

from vimiv.imutils import exif
from vimiv.imutils import metadata
from vimiv.utils import log, is_hex

_logger = log.module_logger(__name__)
Expand All @@ -38,7 +38,7 @@ def prepare_backend(path: Path) -> Optional[pyexiv2.ImageMetadata]:
return None


@exif.register(exif.Operations.copy_metadata)
@metadata.register(metadata.Operations.copy_metadata)
def copy_metadata(path: Path, dest: str, reset_orientation: bool = True) -> bool:
"""Copy metadata from current image to dest."""
metadata = prepare_backend(path)
Expand All @@ -48,7 +48,7 @@ def copy_metadata(path: Path, dest: str, reset_orientation: bool = True) -> bool

if reset_orientation:
with contextlib.suppress(KeyError):
metadata["Exif.Image.Orientation"] = exif.ExifOrientation.Normal
metadata["Exif.Image.Orientation"] = metadata.ExifOrientation.Normal

try:
dest_image = pyexiv2.ImageMetadata(dest)
Expand All @@ -69,7 +69,7 @@ def copy_metadata(path: Path, dest: str, reset_orientation: bool = True) -> bool
return False


@exif.register(exif.Operations.get_date_time)
@metadata.register(metadata.Operations.get_date_time)
def get_date_time(path: Path) -> str:
"""Get creation date and time as formatted string."""
metadata = prepare_backend(path)
Expand All @@ -82,9 +82,9 @@ def get_date_time(path: Path) -> str:
return ""


@exif.register(exif.Operations.get_metadata)
@metadata.register(metadata.Operations.get_metadata)
@functools.lru_cache(1)
def get_metadata(path: Path, desired_keys: Sequence[str]) -> exif.MetadataDictT:
def get_metadata(path: Path, desired_keys: Sequence[str]) -> metadata.MetadataDictT:
"""Get value of all desired keys."""
metadata = prepare_backend(path)
out = {}
Expand Down Expand Up @@ -122,7 +122,7 @@ def get_metadata(path: Path, desired_keys: Sequence[str]) -> exif.MetadataDictT:
return out


@exif.register(exif.Operations.get_keys)
@metadata.register(metadata.Operations.get_keys)
@functools.lru_cache(1)
def get_keys(path: Path) -> Iterable[str]:
"""Retrieve the key of all metadata values available in the current image."""
Expand Down

0 comments on commit 7a609c7

Please sign in to comment.