From b0114c917499d319287bc678aa94cb3e33e07297 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Mon, 8 Feb 2016 01:31:15 -0800 Subject: [PATCH] More logging improvements --- ocrmypdf/main.py | 4 ++-- ocrmypdf/qpdf.py | 30 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/ocrmypdf/main.py b/ocrmypdf/main.py index ffbf20ae..6e47c46d 100755 --- a/ocrmypdf/main.py +++ b/ocrmypdf/main.py @@ -450,7 +450,7 @@ def split_pages( options.input_file)) sys.exit(ExitCode.input_file) - npages = qpdf.get_npages(input_file) + npages = qpdf.get_npages(input_file, log) qpdf.split_pages(input_file, work_folder, npages) from glob import glob @@ -792,7 +792,7 @@ def add_text_layer( else: pass - log.info("{0}: rotating {1} degrees".format( + log.info("{0:4d}: rotating {1} degrees".format( page_number(image), rotation, tx, ty)) page_text.mergeRotatedScaledTranslatedPage( page_image, rotation, 1.0, tx, ty, expand=False) diff --git a/ocrmypdf/qpdf.py b/ocrmypdf/qpdf.py index b17b88c4..dcccc2ec 100644 --- a/ocrmypdf/qpdf.py +++ b/ocrmypdf/qpdf.py @@ -19,15 +19,15 @@ def check(input_file, log): check_output(args_qpdf, stderr=STDOUT, universal_newlines=True) except CalledProcessError as e: if e.returncode == 2: - print("{0}: not a valid PDF, and could not repair it.".format( + log.error("{0}: not a valid PDF, and could not repair it.".format( input_file)) - print("Details:") - print(e.output) + log.error("Details:") + log.error(e.output) elif e.returncode == 3: log.info("qpdf --check returned warnings:") log.info(e.output) else: - print(e.output) + log.warning(e.output) return False return True @@ -40,29 +40,27 @@ def repair(input_file, output_file, log): check_output(args_qpdf, stderr=STDOUT, universal_newlines=True) except CalledProcessError as e: if e.returncode == 3 and e.output.find("operation succeeded"): - log.debug('qpdf found and fixed errors:') + log.debug('qpdf found and fixed errors: ' + e.output) log.debug(e.output) - print(e.output) return if e.returncode == 2 and e.output.find("invalid password"): - print("{0}: this PDF is password-protected - password must " - "be removed for OCR".format(input_file)) + log.error("{0}: this PDF is password-protected - password must " + "be removed for OCR".format(input_file)) sys.exit(ExitCode.input_file) elif e.returncode == 2: - print("{0}: not a valid PDF, and could not repair it.".format( - input_file)) - print("Details:") - print(e.output) + log.error("{0}: not a valid PDF, and could not repair it.".format( + input_file)) + log.error("Details: " + e.output) sys.exit(ExitCode.input_file) else: - print("{0}: unknown error".format( - input_file)) - print(e.output) + log.error("{0}: unknown error".format( + input_file)) + log.error(e.output) sys.exit(ExitCode.unknown) -def get_npages(input_file): +def get_npages(input_file, log): try: pages = check_output( [get_program('qpdf'), '--show-npages', input_file],