Added system checks to warn people of misconfigurations

This commit is contained in:
Daniel Quinn
2017-01-01 18:39:34 +00:00
parent 8fc3d8a27e
commit 30be13ae33
3 changed files with 55 additions and 5 deletions

View File

@@ -0,0 +1 @@
from .checks import paths_check

47
src/paperless/checks.py Normal file
View File

@@ -0,0 +1,47 @@
import os
from django.core.checks import Error, register, Warning
@register()
def paths_check(app_configs, **kwargs):
check_messages = []
exists_message = "{} is set but doesn't exist."
exists_hint = "Create a directory at {}"
writeable_message = "{} is not writeable"
writeable_hint = (
"Set the permissions of {} to be writeable by the user running the "
"Paperless services"
)
directory = os.getenv("PAPERLESS_DBDIR")
if directory:
if not os.path.exists(directory):
check_messages.append(Error(
exists_message.format("PAPERLESS_DBDIR"),
exists_hint.format(directory)
))
if not check_messages:
if not os.access(directory, os.W_OK | os.X_OK):
check_messages.append(Error(
writeable_message.format("PAPERLESS_DBDIR"),
writeable_hint.format(directory)
))
directory = os.getenv("PAPERLESS_MEDIADIR")
if directory:
if not os.path.exists(directory):
check_messages.append(Error(
exists_message.format("PAPERLESS_MEDIADIR"),
exists_hint.format(directory)
))
if not check_messages:
if not os.access(directory, os.W_OK | os.X_OK):
check_messages.append(Error(
writeable_message.format("PAPERLESS_MEDIADIR"),
writeable_hint.format(directory)
))
return check_messages