59d100243d
has_cmd returns a tuple, not a boolean value. This fixes a crash when e.g. "tesseract" is not available in the test_m68k_nextcube test. Reported-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20240910075820.51346-1-thuth@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Thomas Huth <thuth@redhat.com>
37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
# ...
|
|
#
|
|
# Copyright (c) 2019 Philippe Mathieu-Daudé <f4bug@amsat.org>
|
|
#
|
|
# This work is licensed under the terms of the GNU GPL, version 2 or
|
|
# later. See the COPYING file in the top-level directory.
|
|
|
|
import re
|
|
import logging
|
|
|
|
from . import has_cmd, run_cmd
|
|
|
|
def tesseract_available(expected_version):
|
|
(has_tesseract, _) = has_cmd('tesseract')
|
|
if not has_tesseract:
|
|
return False
|
|
(stdout, stderr, ret) = run_cmd([ 'tesseract', '--version'])
|
|
if ret:
|
|
return False
|
|
version = stdout.split()[1]
|
|
return int(version.split('.')[0]) >= expected_version
|
|
|
|
def tesseract_ocr(image_path, tesseract_args=''):
|
|
console_logger = logging.getLogger('console')
|
|
console_logger.debug(image_path)
|
|
(stdout, stderr, ret) = run_cmd(['tesseract', image_path,
|
|
'stdout'])
|
|
if ret:
|
|
return None
|
|
lines = []
|
|
for line in stdout.split('\n'):
|
|
sline = line.strip()
|
|
if len(sline):
|
|
console_logger.debug(sline)
|
|
lines += [sline]
|
|
return lines
|