settings.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. "mathfilters",
  33. "search",
  34. "games",
  35. "rest_framework",
  36. ]
  37. MIDDLEWARE = [
  38. "django.middleware.security.SecurityMiddleware",
  39. "django.contrib.sessions.middleware.SessionMiddleware",
  40. "django.middleware.common.CommonMiddleware",
  41. "django.middleware.csrf.CsrfViewMiddleware",
  42. "django.contrib.auth.middleware.AuthenticationMiddleware",
  43. "django.contrib.messages.middleware.MessageMiddleware",
  44. "django.middleware.clickjacking.XFrameOptionsMiddleware",
  45. ]
  46. X_FRAME_OPTIONS = "SAMEORIGIN"
  47. ROOT_URLCONF = "emus.urls"
  48. TEMPLATES = [
  49. {
  50. "BACKEND": "django.template.backends.django.DjangoTemplates",
  51. "DIRS": [str(BASE_DIR.joinpath("templates"))], # new
  52. "APP_DIRS": True,
  53. "OPTIONS": {
  54. "context_processors": [
  55. "django.template.context_processors.debug",
  56. "django.template.context_processors.request",
  57. "django.contrib.auth.context_processors.auth",
  58. "django.contrib.messages.context_processors.messages",
  59. "games.context_processors.game_systems",
  60. ],
  61. },
  62. },
  63. ]
  64. WSGI_APPLICATION = "emus.wsgi.application"
  65. DATABASES = {
  66. "default": dj_database_url.config(
  67. default=os.getenv("EMUS_DATABASE_URL", "sqlite:///db.sqlite3"), conn_max_age=600
  68. )
  69. }
  70. AUTH_PASSWORD_VALIDATORS = [
  71. {
  72. "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
  73. },
  74. {
  75. "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
  76. },
  77. {
  78. "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
  79. },
  80. {
  81. "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
  82. },
  83. ]
  84. # Internationalization
  85. # https://docs.djangoproject.com/en/3.1/topics/i18n/
  86. LANGUAGE_CODE = "en-us"
  87. TIME_ZONE = "UTC"
  88. USE_I18N = True
  89. USE_L10N = True
  90. USE_TZ = True
  91. # Static files (CSS, JavaScript, Images)
  92. # https://docs.djangoproject.com/en/3.1/howto/static-files/
  93. STATIC_URL = "static/"
  94. STATIC_ROOT = os.getenv("EMUS_STATIC_ROOT", os.path.join(BASE_DIR, "static"))
  95. MEDIA_URL = "/media/"
  96. MEDIA_ROOT = os.getenv("EMUS_MEDIA_ROOT", os.path.join(BASE_DIR, "media"))
  97. ROMS_DIR = os.path.join(MEDIA_ROOT, "roms")
  98. SCRAPER_BIN_PATH = os.getenv("EMUS_SCRAPER_BINPATH", "Skyscraper")
  99. SCRAPER_CONFIG_FILE = os.getenv("EMUS_SCRAPER_CONFIG_FILE", "skyscraper.ini")
  100. SCRAPER_SITE = os.getenv("EMUS_SCRAPER_SITE", "screenscraper")
  101. JSON_LOGGING = os.getenv("EMUS_JSON_LOGGING", False)
  102. LOG_TYPE = "json" if JSON_LOGGING else "log"
  103. RETROPIE_WEBRETRO_SYSTEM_MAP = {
  104. "n64": "mupen64plus_next",
  105. "nes": "nestopia",
  106. "megadrive": "genesis_plus_gx",
  107. "gba": "mgba",
  108. "snes": "snes9x",
  109. }
  110. RETROPIE_RETROARCH_WEB_SYSTEM_MAP = {
  111. "3do": "opera",
  112. "atarijaguar": "virtualjaguar",
  113. "coleco": "bluemsx",
  114. "dreamcast": "flycast",
  115. "gb": "gambatte",
  116. "gba": "mgba",
  117. "gbc": "gambatte",
  118. "gc": "dolphin",
  119. "megadrive": "genesis_plus_gx",
  120. "gamgear": "genesis_plus_gx",
  121. "atarilynx": "handy",
  122. "msx": "bluemsx",
  123. "n64": "mupen64plus_next",
  124. "nds": "desmume",
  125. "ngp": "fbneo",
  126. "ngpc": "fbneo",
  127. "nes": "nestopia",
  128. "pcengine": "mednafen_supergrafx",
  129. "psp": "ppsspp",
  130. "psx": "mednafen_psx",
  131. "saturn": "mednafen_saturn",
  132. "scummvm": "",
  133. "segacd": "genesis_plus_gx",
  134. "snes": "snes9x",
  135. "wii": "dolphin",
  136. }
  137. GAME_SYSTEM_SLUG_MAP = {
  138. "3do": "3DO",
  139. "atarijaguar": "Atari Jaguar",
  140. "atarilynx": "Atari Lynx",
  141. "coleco": "Colecovision",
  142. "dreamcast": "Dreamcast",
  143. "gb": "Game Boy",
  144. "gba": "Game Boy Advance",
  145. "gbc": "Game Boy Color",
  146. "gc": "GameCube",
  147. "megadrive": "Genesis/Mega Drive",
  148. "model3": "Sega Model 3",
  149. "gamgear": "Game Gear",
  150. "msx": "MSX",
  151. "n64": "Nintendo 64",
  152. "nds": "Nintendo DS",
  153. "ngp": "Neo Geo Pocket",
  154. "neogeo": "Neo Geo",
  155. "ngpc": "Neo Geo Pocket Color",
  156. "nes": "Nintendo",
  157. "pcengine": "PC Engine/TurboGrafix 16",
  158. "ps2": "Playstation 2",
  159. "psp": "Playstation Portable",
  160. "psx": "Playstation",
  161. "ports": "Ports",
  162. "saturn": "Saturn",
  163. "scummvm": "ScummVM",
  164. "sega32x": "Sega 32X",
  165. "segacd": "Sega CD",
  166. "snes": "Super Nintendo",
  167. "wii": "Wii",
  168. }
  169. default_level = "INFO"
  170. if DEBUG:
  171. default_level = "DEBUG"
  172. LOG_LEVEL = os.getenv("EMUS_LOG_LEVEL", default_level)
  173. LOG_FILE_PATH = os.getenv("EMUS_LOG_FILE_PATH", "/tmp/")
  174. LOGGING = {
  175. "version": 1,
  176. "disable_existing_loggers": False,
  177. "root": {"handlers": ["console", "file"], "level": LOG_LEVEL, "propagate": True},
  178. "formatters": {
  179. "color": {
  180. "()": "colorlog.ColoredFormatter",
  181. # \r returns caret to line beginning, in tests this eats the silly dot that removes
  182. # the beautiful alignment produced below
  183. "format": "\r"
  184. "{log_color}{levelname:8s}{reset} "
  185. "{bold_cyan}{name}{reset}:"
  186. "{fg_bold_red}{lineno}{reset} "
  187. "{thin_yellow}{funcName} "
  188. "{thin_white}{message}"
  189. "{reset}",
  190. "style": "{",
  191. },
  192. "log": {"format": "%(asctime)s %(levelname)s %(message)s"},
  193. "json": {
  194. "()": "pythonjsonlogger.jsonlogger.JsonFormatter",
  195. "format": "%(levelname)s %(name) %(funcName) %(lineno) %(asctime)s %(message)s",
  196. },
  197. },
  198. "handlers": {
  199. "console": {
  200. "class": "logging.StreamHandler",
  201. "formatter": "color",
  202. "level": LOG_LEVEL,
  203. },
  204. "null": {
  205. "class": "logging.NullHandler",
  206. "level": LOG_LEVEL,
  207. },
  208. "file": {
  209. "class": "logging.handlers.RotatingFileHandler",
  210. "filename": "".join([LOG_FILE_PATH, "emus.", LOG_TYPE]),
  211. "formatter": LOG_TYPE,
  212. "level": LOG_LEVEL,
  213. },
  214. "requests_file": {
  215. "class": "logging.handlers.RotatingFileHandler",
  216. "filename": "".join([LOG_FILE_PATH, "emus_requests.", LOG_TYPE]),
  217. "formatter": LOG_TYPE,
  218. "level": LOG_LEVEL,
  219. },
  220. },
  221. "loggers": {
  222. # Quiet down our console a little
  223. "django.channels.server": {
  224. "handlers": ["requests_file", "console"],
  225. "level": "ERROR",
  226. "propagate": False,
  227. },
  228. "django": {
  229. "handlers": ["file"],
  230. "propagate": True,
  231. },
  232. "daphne": {"handlers": ["file"], "propagate": False},
  233. "django.db.backends": {"handlers": ["null"]},
  234. "emus": {"handlers": ["console", "file"], "propagate": True},
  235. },
  236. }
  237. REMOVE_FROM_SLUGS = ["_", " ", "/"]
  238. if DEBUG:
  239. # We clear out a db with lots of games all the time in dev
  240. DATA_UPLOAD_MAX_NUMBER_FIELDS = 3000