|
@@ -1,16 +1,16 @@
|
|
|
-"""
|
|
|
-Django settings for emus project.
|
|
|
-
|
|
|
-Generated by 'django-admin startproject' using Django 3.1.2.
|
|
|
+import os
|
|
|
|
|
|
-For more information on this file, see
|
|
|
-https://docs.djangoproject.com/en/3.1/topics/settings/
|
|
|
+from django.utils.translation import gettext_lazy as _
|
|
|
+from dotenv import load_dotenv
|
|
|
|
|
|
-For the full list of settings and their values, see
|
|
|
-https://docs.djangoproject.com/en/3.1/ref/settings/
|
|
|
-"""
|
|
|
+# Tap emus.conf if it's available
|
|
|
+if os.path.exists("emus.conf"):
|
|
|
+ load_dotenv("emus.conf")
|
|
|
+elif os.path.exists("/etc/emus.conf"):
|
|
|
+ load_dotenv("/etc/emus.conf")
|
|
|
+elif os.path.exists("/usr/local/etc/emus.conf"):
|
|
|
+ load_dotenv("/usr/local/etc/emus.conf")
|
|
|
|
|
|
-import os
|
|
|
from pathlib import Path
|
|
|
|
|
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
|
@@ -126,9 +126,83 @@ MEDIA_ROOT = os.path.join(BASE_DIR, "media")
|
|
|
ROMS_DIR = os.path.join(MEDIA_ROOT, "roms")
|
|
|
|
|
|
SCRAPER_CONFIG = {
|
|
|
- "site": os.getenv("SCRAPER_SITE", "screenscraper"),
|
|
|
- "user": os.getenv("SCRAPER_USER", None),
|
|
|
- "pass": os.getenv("SCRAPER_PASS", None),
|
|
|
- "threads": os.getenv("SCRAPER_THREADS", 2),
|
|
|
- "bin_path": os.getenv("SCRAPER_BINPATH", "Skyscraper"),
|
|
|
+ "site": os.getenv("EMUS_SCRAPER_SITE", "screenscraper"),
|
|
|
+ "user": os.getenv("EMUS_SCRAPER_USER", None),
|
|
|
+ "pass": os.getenv("EMUS_SCRAPER_PASS", None),
|
|
|
+ "threads": os.getenv("EMUS_SCRAPER_THREADS", 2),
|
|
|
+ "bin_path": os.getenv("EMUS_SCRAPER_BINPATH", "Skyscraper"),
|
|
|
+}
|
|
|
+
|
|
|
+JSON_LOGGING = os.getenv("EMUS_JSON_LOGGING", False)
|
|
|
+LOG_TYPE = "json" if JSON_LOGGING else "log"
|
|
|
+
|
|
|
+default_level = "INFO"
|
|
|
+if DEBUG:
|
|
|
+ default_level = "DEBUG"
|
|
|
+
|
|
|
+LOG_LEVEL = os.getenv("EMUS_LOG_LEVEL", default_level)
|
|
|
+LOG_FILE_PATH = os.getenv("EMUS_LOG_FILE_PATH", "/tmp/")
|
|
|
+
|
|
|
+LOGGING = {
|
|
|
+ "version": 1,
|
|
|
+ "disable_existing_loggers": False,
|
|
|
+ "root": {"handlers": ["console", "file"], "level": LOG_LEVEL, "propagate": True},
|
|
|
+ "formatters": {
|
|
|
+ "color": {
|
|
|
+ "()": "colorlog.ColoredFormatter",
|
|
|
+ # \r returns caret to line beginning, in tests this eats the silly dot that removes
|
|
|
+ # the beautiful alignment produced below
|
|
|
+ "format": "\r"
|
|
|
+ "{log_color}{levelname:8s}{reset} "
|
|
|
+ "{bold_cyan}{name}{reset}:"
|
|
|
+ "{fg_bold_red}{lineno}{reset} "
|
|
|
+ "{thin_yellow}{funcName} "
|
|
|
+ "{thin_white}{message}"
|
|
|
+ "{reset}",
|
|
|
+ "style": "{",
|
|
|
+ },
|
|
|
+ "log": {"format": "%(asctime)s %(levelname)s %(message)s"},
|
|
|
+ "json": {
|
|
|
+ "()": "pythonjsonlogger.jsonlogger.JsonFormatter",
|
|
|
+ "format": "%(levelname)s %(name) %(funcName) %(lineno) %(asctime)s %(message)s",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "handlers": {
|
|
|
+ "console": {
|
|
|
+ "class": "logging.StreamHandler",
|
|
|
+ "formatter": "color",
|
|
|
+ "level": LOG_LEVEL,
|
|
|
+ },
|
|
|
+ "null": {
|
|
|
+ "class": "logging.NullHandler",
|
|
|
+ "level": LOG_LEVEL,
|
|
|
+ },
|
|
|
+ "file": {
|
|
|
+ "class": "logging.handlers.RotatingFileHandler",
|
|
|
+ "filename": "".join([LOG_FILE_PATH, "emus.", LOG_TYPE]),
|
|
|
+ "formatter": LOG_TYPE,
|
|
|
+ "level": LOG_LEVEL,
|
|
|
+ },
|
|
|
+ "requests_file": {
|
|
|
+ "class": "logging.handlers.RotatingFileHandler",
|
|
|
+ "filename": "".join([LOG_FILE_PATH, "emus_requests.", LOG_TYPE]),
|
|
|
+ "formatter": LOG_TYPE,
|
|
|
+ "level": LOG_LEVEL,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "loggers": {
|
|
|
+ # Quiet down our console a little
|
|
|
+ "django.channels.server": {
|
|
|
+ "handlers": ["requests_file", "console"],
|
|
|
+ "level": "ERROR",
|
|
|
+ "propagate": False,
|
|
|
+ },
|
|
|
+ "django": {
|
|
|
+ "handlers": ["file"],
|
|
|
+ "propagate": True,
|
|
|
+ },
|
|
|
+ "daphne": {"handlers": ["file"], "propagate": False},
|
|
|
+ "django.db.backends": {"handlers": ["null"]},
|
|
|
+ "emus": {"handlers": ["console", "file"], "propagate": True},
|
|
|
+ },
|
|
|
}
|