olmocr/pdelfin/check.py

21 lines
771 B
Python
Raw Normal View History

2024-11-01 16:57:19 +00:00
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)
2024-11-01 17:13:11 +00:00
if result.returncode == 0 and result.stderr.startswith("pdftoppm"):
2024-11-01 16:57:19 +00:00
logger.info("pdftoppm is installed and working.")
else:
2024-11-01 17:13:11 +00:00
logger.error(f"pdftoppm is installed but returned an error.")
2024-11-01 16:57:19 +00:00
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")
2024-11-01 17:13:11 +00:00
sys.exit(1)
if __name__ == "__main__":
check_poppler_version()