示例#1
0
def test_shim_paths(tmp_path):
    from ocrmypdf.subprocess._windows import shim_env_path

    progfiles = tmp_path / 'Program Files'
    progfiles.mkdir()
    (progfiles / 'tesseract-ocr').mkdir()
    (progfiles / 'gs' / '9.51' / 'bin').mkdir(parents=True)
    (progfiles / 'gs' / '9.52' / 'bin').mkdir(parents=True)
    syspath = tmp_path / 'bin'
    env = {'PROGRAMFILES': str(progfiles), 'PATH': str(syspath)}

    result_str = shim_env_path(env=env)
    results = result_str.split(os.pathsep)
    assert results[0] == str(syspath), results
    assert results[-3].endswith('tesseract-ocr'), results
    assert results[-2].endswith(os.path.join('gs', '9.52', 'bin')), results
    assert results[-1].endswith(os.path.join('gs', '9.51', 'bin')), results
示例#2
0
from io import BytesIO, UnsupportedOperation
from os import fspath
from tempfile import TemporaryFile

from ocrmypdf.exceptions import MissingDependencyError
from ocrmypdf.lib._leptonica import ffi

# pylint: disable=protected-access

logger = logging.getLogger(__name__)

if os.name == 'nt':
    from ocrmypdf.subprocess._windows import shim_env_path

    libname = 'liblept-5'
    os.environ['PATH'] = shim_env_path()
else:
    libname = 'lept'
_libpath = find_library(libname)
if not _libpath:
    raise MissingDependencyError("""
        ---------------------------------------------------------------------
        This error normally occurs when ocrmypdf can't find the Leptonica
        library, which is usually installed with Tesseract OCR. It could be that
        Tesseract is not installed properly, we can't find the installation
        on your system PATH environment variable.

        The library we are looking for is usually called:
            liblept-5.dll   (Windows)
            liblept*.dylib  (macOS)
            liblept*.so     (Linux/BSD)