diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2019-10-11 08:53:55 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2019-10-11 08:54:07 +0200 |
commit | a0da6a4eb3c8ef5111531ffa81f911924ba2fd3d (patch) | |
tree | f9f12748b4c504f110c52b3a09e1e6ef45eb030d | |
parent | 2e1b8a9302f01222a70ab43faacdd4c4f4532731 (diff) | |
download | epubgrep-a0da6a4eb3c8ef5111531ffa81f911924ba2fd3d.tar.gz |
More exception handling.
-rwxr-xr-x | epubgrep.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/epubgrep.py b/epubgrep.py index 74a7c8a..b62c67a 100755 --- a/epubgrep.py +++ b/epubgrep.py @@ -3,6 +3,7 @@ import argparse import logging import os.path import re +import sys import zipfile from typing import Any, Dict, List, Optional, Tuple @@ -31,7 +32,10 @@ def grep_book(filename: str, pattern: str, flags: int, counting: bool=False, col mline = flags & re.M == re.M - metadata = epub_meta.get_epub_metadata(filename) + try: + metadata = epub_meta.get_epub_metadata(filename) + except epub_meta.EPubException as ex: + log.exception('Failed to open {}'.format(filename)) book = zipfile.ZipFile(filename) printed_booktitle = False @@ -110,4 +114,7 @@ if __name__ == "__main__": for filename in args.files: book_fname = os.path.realpath(filename) - grep_book(book_fname, args.pattern, search_flags, args.count, args.color) + try: + grep_book(book_fname, args.pattern, search_flags, args.count, args.color) + except BrokenPipeError: + sys.exit() |