From 7a609c71b16bd1575a46fe33a72f44072d7c0001 Mon Sep 17 00:00:00 2001 From: Jean-Claude Graf Date: Sun, 8 Jan 2023 11:27:55 +0100 Subject: [PATCH] Rename `imutils.exif` to `imutils.metadata` Renaming is done as this file handles all metadata related functionalities and not just exif metadata. --- vimiv/gui/metadatawidget.py | 10 +++++----- vimiv/imutils/__init__.py | 2 +- vimiv/imutils/_file_handler.py | 8 ++++---- vimiv/imutils/filelist.py | 4 ++-- vimiv/imutils/{exif.py => metadata.py} | 0 vimiv/plugins/metadata_piexif.py | 14 +++++++------- vimiv/plugins/metadata_py3exiv2.py | 14 +++++++------- 7 files changed, 26 insertions(+), 26 deletions(-) rename vimiv/imutils/{exif.py => metadata.py} (100%) diff --git a/vimiv/gui/metadatawidget.py b/vimiv/gui/metadatawidget.py index 70ce3a491..2d2fbf66e 100644 --- a/vimiv/gui/metadatawidget.py +++ b/vimiv/gui/metadatawidget.py @@ -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. @@ -59,7 +59,7 @@ 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) @@ -67,10 +67,10 @@ def __init__(self, parent: QWidget): 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) diff --git a/vimiv/imutils/__init__.py b/vimiv/imutils/__init__.py index 784d232b2..8211e12cd 100644 --- a/vimiv/imutils/__init__.py +++ b/vimiv/imutils/__init__.py @@ -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 diff --git a/vimiv/imutils/_file_handler.py b/vimiv/imutils/_file_handler.py index 3e60a5c06..fbb71bcf9 100644 --- a/vimiv/imutils/_file_handler.py +++ b/vimiv/imutils/_file_handler.py @@ -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) @@ -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 diff --git a/vimiv/imutils/filelist.py b/vimiv/imutils/filelist.py index bf9c9eafd..8bdff3ea8 100644 --- a/vimiv/imutils/filelist.py +++ b/vimiv/imutils/filelist.py @@ -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 "" diff --git a/vimiv/imutils/exif.py b/vimiv/imutils/metadata.py similarity index 100% rename from vimiv/imutils/exif.py rename to vimiv/imutils/metadata.py diff --git a/vimiv/plugins/metadata_piexif.py b/vimiv/plugins/metadata_piexif.py index 1ac80c6b4..e998f65db 100644 --- a/vimiv/plugins/metadata_piexif.py +++ b/vimiv/plugins/metadata_piexif.py @@ -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__) @@ -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) @@ -58,7 +58,7 @@ 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 @@ -66,7 +66,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) @@ -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 = {} @@ -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.""" diff --git a/vimiv/plugins/metadata_py3exiv2.py b/vimiv/plugins/metadata_py3exiv2.py index 45d254b00..5b80928c5 100644 --- a/vimiv/plugins/metadata_py3exiv2.py +++ b/vimiv/plugins/metadata_py3exiv2.py @@ -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__) @@ -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) @@ -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) @@ -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) @@ -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 = {} @@ -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."""