From 75884285cf7d6e387a1d2342d31d7f00733f6184 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sat, 14 Jan 2017 18:04:15 +0000 Subject: [PATCH] Added checks for expected binaries in the PATH Fixes #112 --- src/paperless/__init__.py | 2 +- src/paperless/checks.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/paperless/__init__.py b/src/paperless/__init__.py index c8c4b305b..0789cc963 100644 --- a/src/paperless/__init__.py +++ b/src/paperless/__init__.py @@ -1 +1 @@ -from .checks import paths_check +from .checks import paths_check, binaries_check diff --git a/src/paperless/checks.py b/src/paperless/checks.py index a85d94e0b..f57a838bb 100644 --- a/src/paperless/checks.py +++ b/src/paperless/checks.py @@ -1,10 +1,15 @@ import os +import shutil +from django.conf import settings from django.core.checks import Error, register, Warning @register() def paths_check(app_configs, **kwargs): + """ + Check the various paths for existence, readability and writeability + """ check_messages = [] @@ -45,3 +50,23 @@ def paths_check(app_configs, **kwargs): )) return check_messages + + +@register() +def binaries_check(app_configs, **kwargs): + """ + Paperless requires the existence of a few binaries, so we do some checks + for those here. + """ + + error = "Paperless can't find {}. Without it, consumption is impossible." + hint = "Either it's not in your ${PATH} or it's not installed." + + binaries = (settings.CONVERT_BINARY, settings.UNPAPER_BINARY, "tesseract") + + check_messages = [] + for binary in binaries: + if shutil.which(binary) is None: + check_messages.append(Warning(error.format(binary), hint)) + + return check_messages