RhetTbull / osxphotos

Python app to work with pictures and associated metadata from Apple Photos on macOS. Also includes a package to provide programmatic access to the Photos library, pictures, and metadata.
MIT License
1.76k stars 93 forks source link

Gracefully handle Ctrl+C in all CLI commands #1501

Open RhetTbull opened 1 month ago

RhetTbull commented 1 month ago

Hitting Ctrl+C while a CLI command is running yields a traceback like below. It would be better to catch this and gracefully exit with a nice message like "Aborted!" or such instead of a full traceback.

^CTraceback (most recent call last):
  File "/Users/rhet/.local/bin/osxphotos", line 5, in <module>
    from osxphotos.__main__ import cli_main
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/osxphotos/__init__.py", line 13, in <module>
    from .exifwriter import ExifWriter
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/osxphotos/exifwriter.py", line 19, in <module>
    from .exportoptions import ExportOptions
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/osxphotos/exportoptions.py", line 10, in <module>
    from .export_db import ExportDB
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/osxphotos/export_db.py", line 29, in <module>
    from .fileutil import FileUtil
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/osxphotos/fileutil.py", line 12, in <module>
    from .imageconverter import ImageConverter
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/osxphotos/imageconverter.py", line 18, in <module>
    import Quartz
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/Quartz/__init__.py", line 47, in <module>
    globals().pop("_setup")()
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/Quartz/__init__.py", line 10, in _setup
    from . import (
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/Quartz/QuickLookUI/__init__.py", line 46, in <module>
    globals().pop("_setup")()
  File "/Users/rhet/.local/pipx/venvs/osxphotos/lib/python3.11/site-packages/Quartz/QuickLookUI/__init__.py", line 15, in _setup
    from . import _metadata, _QuickLookUI
KeyboardInterrupt