From 0aead1fbe6578240476bb36a135859b5126f4966 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Thu, 3 Mar 2016 17:59:27 +0000 Subject: [PATCH] #68: Using dotenv for a proper unix config file --- docs/changelog.rst | 3 +++ requirements.txt | 1 + scripts/paperless-consumer.service | 3 +-- scripts/paperless-webserver.service | 1 - src/paperless/settings.py | 16 ++++++++++++---- 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index ce2a4edab..772e30dc0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -3,6 +3,8 @@ Changelog * 0.1.1 (master) + * `#68`_: Added support for using a proper config file at + ``/etc/paperless.conf``. * Refactored the Vagrant installation process to use environment variables rather than asking the user to modify ``settings.py``. * `#44`_: Harmonise environment variable names with constant names. @@ -79,3 +81,4 @@ Changelog .. _#54: https://github.com/danielquinn/paperless/issues/54 .. _#57: https://github.com/danielquinn/paperless/issues/57 .. _#60: https://github.com/danielquinn/paperless/issues/60 +.. _#68: https://github.com/danielquinn/paperless/issues/68 diff --git a/requirements.txt b/requirements.txt index 810af8ec2..6a133327a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ Django==1.9.2 django-extensions==1.6.1 djangorestframework==3.3.2 +python-dotenv==0.3.0 filemagic==1.6 langdetect==1.0.5 Pillow==3.1.1 diff --git a/scripts/paperless-consumer.service b/scripts/paperless-consumer.service index 34d65dedb..79a27d3ce 100644 --- a/scripts/paperless-consumer.service +++ b/scripts/paperless-consumer.service @@ -2,10 +2,9 @@ Description=Paperless consumer [Service] -EnvironmentFile=/etc/conf.d/paperless User=paperless Group=paperless -ExecStart=/home/paperless/project/virtualenv/bin/python /home/paperless/project/src/manage.py document_consumer -v $PAPERLESS_CONSUMPTION_VERBOSITY +ExecStart=/home/paperless/project/virtualenv/bin/python /home/paperless/project/src/manage.py document_consumer [Install] WantedBy=multi-user.target diff --git a/scripts/paperless-webserver.service b/scripts/paperless-webserver.service index 1a2386471..9d20f5a1c 100644 --- a/scripts/paperless-webserver.service +++ b/scripts/paperless-webserver.service @@ -2,7 +2,6 @@ Description=Paperless webserver [Service] -EnvironmentFile=/etc/conf.d/paperless User=paperless Group=paperless ExecStart=/home/paperless/project/virtualenv/bin/python /home/paperless/project/src/manage.py runserver 0.0.0.0:8000 diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 1599a08e8..f2fb41941 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -12,6 +12,8 @@ https://docs.djangoproject.com/en/1.9/ref/settings/ import os +from dotenv import load_dotenv + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -140,6 +142,16 @@ STATIC_URL = '/static/' MEDIA_URL = "/media/" +# Paperless-specific stuff +# You shouldn't have to edit any of these values. Rather, you can set these +# values in /etc/paperless.conf instead. +# ---------------------------------------------------------------------------- + +# Tap paperless.conf if it's available +if os.path.exists("/etc/paperless.conf"): + load_dotenv("/etc/paperless.conf") + + # Logging LOGGING = { @@ -159,10 +171,6 @@ LOGGING = { } -# Paperless-specific stuff -# Change these paths if yours are different -# ---------------------------------------------------------------------------- - # The default language that tesseract will attempt to use when parsing # documents. It should be a 3-letter language code consistent with ISO 639. OCR_LANGUAGE = "eng"