Refactor shared script helpers

This commit is contained in:
ajp_anton
2026-06-08 02:55:31 +00:00
parent ae05bc9710
commit b6024d8b65
10 changed files with 855 additions and 356 deletions
+7 -22
View File
@@ -13,18 +13,10 @@ from __future__ import annotations
import subprocess
import sys
from pathlib import Path
from shutil import which
def first_file_from_path(path: Path) -> Path | None:
path = path.expanduser()
if path.is_file():
return path.resolve()
if path.is_dir():
for child in sorted(path.rglob("*"), key=lambda item: str(item).lower()):
if child.is_file():
return child.resolve()
return None
from tools.console import pause_if_interactive
from tools.exiftool import require_exiftool
from tools.filesystem import first_file_from_path
def choose_file(args: list[str]) -> Path | None:
@@ -35,22 +27,15 @@ def choose_file(args: list[str]) -> Path | None:
return None
def pause_if_interactive() -> None:
if sys.stdin.isatty():
try:
input("\nPress Enter to close...")
except EOFError:
pass
def run(argv: list[str]) -> int:
if len(argv) < 2:
print("Usage: python3 view_metadata.py path/to/file/or/directory [...]")
return 2
exiftool = which("exiftool")
if exiftool is None:
print("exiftool was not found on PATH.")
try:
exiftool = require_exiftool()
except RuntimeError as exc:
print(exc)
return 1
file_path = choose_file(argv[1:])