From 52dc74d3cee9c82fccd2093dba5b5cd43c705bec Mon Sep 17 00:00:00 2001 From: Jim Barlow Date: Wed, 11 Feb 2015 10:24:10 -0800 Subject: [PATCH] Support Tesseract 3.03 quirk: .html vs .hocr extension --- src/ocrpage.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ocrpage.py b/src/ocrpage.py index 6c6bf6cc..b5b3bcfe 100755 --- a/src/ocrpage.py +++ b/src/ocrpage.py @@ -185,6 +185,10 @@ def re_symlink(input_file, soft_link_name, logger, logger_mutex): except: with logger_mutex: logger.debug("Can't unlink %s" % (soft_link_name)) + + if not os.path.exists(input_file): + raise Exception("trying to create a broken symlink to %s" % input_file) + with logger_mutex: logger.debug("os.symlink(%s, %s)" % (input_file, soft_link_name)) @@ -509,8 +513,14 @@ def ocr_tesseract( if p.returncode != 0: raise CalledProcessError(p.returncode, args_tesseract) - # Tesseract appends suffix ".html" on its own - re_symlink(output_file + ".html", output_file, logger, logger_mutex) + if os.path.exists(output_file + '.html'): + # Tesseract 3.02 appends suffix ".html" on its own + re_symlink(output_file + ".html", output_file, + logger, logger_mutex) + elif os.path.exists(output_file + '.hocr'): + # Tesseract 3.03 appends suffix ".hocr" on its own + re_symlink(output_file + ".hocr", output_file, + logger, logger_mutex) @active_if(ocr_required)