olmocr/pdelfin/check.py
Jake Poznanski 5ebc8cdd88 Checkfix
2024-11-01 17:13:11 +00:00

21 lines
771 B
Python

import sys
import subprocess
import logging
logger = logging.getLogger(__name__)
def check_poppler_version():
try:
result = subprocess.run(['pdftoppm', '-h'], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
if result.returncode == 0 and result.stderr.startswith("pdftoppm"):
logger.info("pdftoppm is installed and working.")
else:
logger.error(f"pdftoppm is installed but returned an error.")
sys.exit(1)
except FileNotFoundError:
logger.error("pdftoppm is not installed.")
logger.error("Check the README in the https://github.com/allenai/pdelfin/blob/main/README.md for installation instructions")
sys.exit(1)
if __name__ == "__main__":
check_poppler_version()