From 22a7cd34210334334b3a5c8035b4db78e9d3d5d3 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 30 Oct 2018 16:19:13 -0700 Subject: [PATCH] Add argument checks for --redo-ocr --- src/ocrmypdf/__main__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ocrmypdf/__main__.py b/src/ocrmypdf/__main__.py index bea152cf..8fb4589f 100755 --- a/src/ocrmypdf/__main__.py +++ b/src/ocrmypdf/__main__.py @@ -477,6 +477,13 @@ def check_options_output(options, log): lossless_reconstruction = True options.lossless_reconstruction = lossless_reconstruction + if not options.lossless_reconstruction and options.redo_ocr: + raise argparse.ArgumentError( + None, + "--redo-ocr is not currently compatible with --deskew, " + "--clean-final, and --remove-background" + ) + def check_options_sidecar(options, log): if options.sidecar == '\0': @@ -521,10 +528,15 @@ def check_options_preprocessing(options, log): def check_options_ocr_behavior(options, log): - if options.force_ocr and options.skip_text: + exclusive_options = sum( + [(1 if opt else 0) + for opt in (options.force_ocr, options.skip_text, options.redo_ocr) + ] + ) + if exclusive_options >= 2: raise argparse.ArgumentError( None, - "Error: --force-ocr and --skip-text are mutually exclusive.") + "Error: choose only one of --force-ocr, --skip-text, --redo-ocr.") def check_options_optimizing(options, log):