settings.py 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import dj_database_url
  2. import os
  3. from django.utils.translation import gettext_lazy as _
  4. from dotenv import load_dotenv
  5. # Tap emus.conf if it's available
  6. if os.path.exists("emus.conf"):
  7. load_dotenv("emus.conf")
  8. elif os.path.exists("/etc/emus.conf"):
  9. load_dotenv("/etc/emus.conf")
  10. elif os.path.exists("/usr/local/etc/emus.conf"):
  11. load_dotenv("/usr/local/etc/emus.conf")
  12. from pathlib import Path
  13. # Build paths inside the project like this: BASE_DIR / 'subdir'.
  14. BASE_DIR = Path(__file__).resolve().parent.parent
  15. # Quick-start development settings - unsuitable for production
  16. # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
  17. # SECURITY WARNING: keep the secret key used in production secret!
  18. SECRET_KEY = "l2-2d4dmvb0un0s)=5z%c87t*tg_hu&bt6*o^ks9r7f-3(mp$$"
  19. # SECURITY WARNING: don't run with debug turned on in production!
  20. DEBUG = True
  21. ALLOWED_HOSTS = ["*"]
  22. # Application definition
  23. INSTALLED_APPS = [
  24. "django.contrib.admin",
  25. "django.contrib.auth",
  26. "django.contrib.contenttypes",
  27. "django.contrib.sessions",
  28. "django.contrib.messages",
  29. "django.contrib.staticfiles",
  30. "django_extensions",
  31. "emus",
  32. "games",
  33. "search",
  34. "rest_framework",
  35. ]
  36. MIDDLEWARE = [
  37. "django.middleware.security.SecurityMiddleware",
  38. "django.contrib.sessions.middleware.SessionMiddleware",
  39. "django.middleware.common.CommonMiddleware",
  40. "django.middleware.csrf.CsrfViewMiddleware",
  41. "django.contrib.auth.middleware.AuthenticationMiddleware",
  42. "django.contrib.messages.middleware.MessageMiddleware",
  43. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  44. ]
  45. X_FRAME_OPTIONS = "SAMEORIGIN"
  46. ROOT_URLCONF = "emus.urls"
  47. TEMPLATES = [
  48. {
  49. "BACKEND": "django.template.backends.django.DjangoTemplates",
  50. "DIRS": [str(BASE_DIR.joinpath("templates"))], # new
  51. "APP_DIRS": True,
  52. "OPTIONS": {
  53. "context_processors": [
  54. "django.template.context_processors.debug",
  55. "django.template.context_processors.request",
  56. "django.contrib.auth.context_processors.auth",
  57. "django.contrib.messages.context_processors.messages",
  58. "games.context_processors.game_systems",
  59. ],
  60. },
  61. },
  62. ]
  63. WSGI_APPLICATION = "emus.wsgi.application"
  64. DATABASE_URL = os.getenv("EMUS_DATABASE_URL", "sqlite:///db.sqlite3")
  65. AUTH_PASSWORD_VALIDATORS = [
  66. {
  67. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  68. },
  69. {
  70. "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  71. },
  72. {
  73. "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
  74. },
  75. {
  76. "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
  77. },
  78. ]
  79. # Internationalization
  80. # https://docs.djangoproject.com/en/3.1/topics/i18n/
  81. LANGUAGE_CODE = "en-us"
  82. TIME_ZONE = "UTC"
  83. USE_I18N = True
  84. USE_L10N = True
  85. USE_TZ = True
  86. # Static files (CSS, JavaScript, Images)
  87. # https://docs.djangoproject.com/en/3.1/howto/static-files/
  88. STATIC_URL = "static/"
  89. STATIC_ROOT = os.getenv("EMUS_STATIC_ROOT", os.path.join(BASE_DIR, "static"))
  90. MEDIA_URL = "/media/"
  91. MEDIA_ROOT = os.getenv("EMUS_MEDIA_ROOT", os.path.join(BASE_DIR, "media"))
  92. ROMS_DIR = os.path.join(MEDIA_ROOT, "roms")
  93. SCRAPER_BIN_PATH = os.getenv("EMUS_SCRAPER_BINPATH", "Skyscraper")
  94. SCRAPER_CONFIG_FILE = os.getenv("EMUS_SCRAPER_CONFIG_FILE", "skyscraper.ini")
  95. SCRAPER_SITE = os.getenv("EMUS_SCRAPER_SITE", "screenscraper")
  96. JSON_LOGGING = os.getenv("EMUS_JSON_LOGGING", False)
  97. LOG_TYPE = "json" if JSON_LOGGING else "log"
  98. RETROPIE_WEBRETRO_SYSTEM_MAP = {
  99. "n64": "mupen64plus_next",
  100. "nes": "nestopia",
  101. "megadrive": "genesis_plus_gx",
  102. "gba": "mgba",
  103. "snes": "snes9x",
  104. }
  105. RETROPIE_RETROARCH_WEB_SYSTEM_MAP = {
  106. "3do": "opera",
  107. "atarijaguar": "virtualjaguar",
  108. "coleco": "bluemsx",
  109. "dreamcast": "flycast",
  110. "gb": "gambatte",
  111. "gba": "mgba",
  112. "gbc": "gambatte",
  113. "gc": "dolphin",
  114. "megadrive": "genesis_plus_gx",
  115. "gamgear": "genesis_plus_gx",
  116. "atarilynx": "handy",
  117. "msx": "bluemsx",
  118. "n64": "mupen64plus_next",
  119. "nds": "desmume",
  120. "ngp": "fbneo",
  121. "ngpc": "fbneo",
  122. "nes": "nestopia",
  123. "pcengine": "mednafen_supergrafx",
  124. "psp": "ppsspp",
  125. "psx": "mednafen_psx",
  126. "saturn": "mednafen_saturn",
  127. "scummvm": "",
  128. "segacd": "genesis_plus_gx",
  129. "snes": "snes9x",
  130. "wii": "dolphin",
  131. }
  132. default_level = "INFO"
  133. if DEBUG:
  134. default_level = "DEBUG"
  135. LOG_LEVEL = os.getenv("EMUS_LOG_LEVEL", default_level)
  136. LOG_FILE_PATH = os.getenv("EMUS_LOG_FILE_PATH", "/tmp/")
  137. LOGGING = {
  138. "version": 1,
  139. "disable_existing_loggers": False,
  140. "root": {"handlers": ["console", "file"], "level": LOG_LEVEL, "propagate": True},
  141. "formatters": {
  142. "color": {
  143. "()": "colorlog.ColoredFormatter",
  144. # \r returns caret to line beginning, in tests this eats the silly dot that removes
  145. # the beautiful alignment produced below
  146. "format": "\r"
  147. "{log_color}{levelname:8s}{reset} "
  148. "{bold_cyan}{name}{reset}:"
  149. "{fg_bold_red}{lineno}{reset} "
  150. "{thin_yellow}{funcName} "
  151. "{thin_white}{message}"
  152. "{reset}",
  153. "style": "{",
  154. },
  155. "log": {"format": "%(asctime)s %(levelname)s %(message)s"},
  156. "json": {
  157. "()": "pythonjsonlogger.jsonlogger.JsonFormatter",
  158. "format": "%(levelname)s %(name) %(funcName) %(lineno) %(asctime)s %(message)s",
  159. },
  160. },
  161. "handlers": {
  162. "console": {
  163. "class": "logging.StreamHandler",
  164. "formatter": "color",
  165. "level": LOG_LEVEL,
  166. },
  167. "null": {
  168. "class": "logging.NullHandler",
  169. "level": LOG_LEVEL,
  170. },
  171. "file": {
  172. "class": "logging.handlers.RotatingFileHandler",
  173. "filename": "".join([LOG_FILE_PATH, "emus.", LOG_TYPE]),
  174. "formatter": LOG_TYPE,
  175. "level": LOG_LEVEL,
  176. },
  177. "requests_file": {
  178. "class": "logging.handlers.RotatingFileHandler",
  179. "filename": "".join([LOG_FILE_PATH, "emus_requests.", LOG_TYPE]),
  180. "formatter": LOG_TYPE,
  181. "level": LOG_LEVEL,
  182. },
  183. },
  184. "loggers": {
  185. # Quiet down our console a little
  186. "django.channels.server": {
  187. "handlers": ["requests_file", "console"],
  188. "level": "ERROR",
  189. "propagate": False,
  190. },
  191. "django": {
  192. "handlers": ["file"],
  193. "propagate": True,
  194. },
  195. "daphne": {"handlers": ["file"], "propagate": False},
  196. "django.db.backends": {"handlers": ["null"]},
  197. "emus": {"handlers": ["console", "file"], "propagate": True},
  198. },
  199. }
  200. REMOVE_FROM_SLUGS = ["_", " ", "/"]
  201. if DEBUG:
  202. # We clear out a db with lots of games all the time in dev
  203. DATA_UPLOAD_MAX_NUMBER_FIELDS = 3000