From b2b66d134482f559922c072f2bddd7e0948207cc Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Thu, 17 Dec 2015 11:20:20 +0800 Subject: [PATCH 1/2] Don't exit when qpdf repair was successful --- ocrmypdf/main.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index 7bc4d6ff..a93b7ae6 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -356,14 +356,20 @@ def repair_pdf( try: out = check_output(args_qpdf, stderr=STDOUT, universal_newlines=True) except CalledProcessError as e: + exit_with_error = 1 if e.returncode == 2: print("{0}: not a valid PDF, and could not repair it.".format( options.input_file)) print("Details:") print(e.output) + elif e.returncode == 3 and e.output.find("operation succeeded"): + exit_with_error = 0 + out = e.output + print(e.output) else: print(e.output) - sys.exit(ExitCode.input_file) + if exit_with_error == 1: + sys.exit(ExitCode.input_file) log.debug(out) From d7c7559b05d49a461c5a41a21fa7082ea827c77e Mon Sep 17 00:00:00 2001 From: Shem Pasamba Date: Thu, 17 Dec 2015 11:23:27 +0800 Subject: [PATCH 2/2] Use boolean instead of integers --- ocrmypdf/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index a93b7ae6..5a355588 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -356,19 +356,19 @@ def repair_pdf( try: out = check_output(args_qpdf, stderr=STDOUT, universal_newlines=True) except CalledProcessError as e: - exit_with_error = 1 + exit_with_error = True if e.returncode == 2: print("{0}: not a valid PDF, and could not repair it.".format( options.input_file)) print("Details:") print(e.output) elif e.returncode == 3 and e.output.find("operation succeeded"): - exit_with_error = 0 + exit_with_error = False out = e.output print(e.output) else: print(e.output) - if exit_with_error == 1: + if exit_with_error: sys.exit(ExitCode.input_file) log.debug(out)