settings.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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 = os.getenv("EMUS_TIME_ZONE", "EST")
  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. default_level = "INFO"
  104. if DEBUG:
  105. default_level = "DEBUG"
  106. LOG_LEVEL = os.getenv("EMUS_LOG_LEVEL", default_level)
  107. LOG_FILE_PATH = os.getenv("EMUS_LOG_FILE_PATH", "/tmp/")
  108. LOGGING = {
  109. "version": 1,
  110. "disable_existing_loggers": False,
  111. "root": {"handlers": ["console", "file"], "level": LOG_LEVEL, "propagate": True},
  112. "formatters": {
  113. "color": {
  114. "()": "colorlog.ColoredFormatter",
  115. # \r returns caret to line beginning, in tests this eats the silly dot that removes
  116. # the beautiful alignment produced below
  117. "format": "\r"
  118. "{log_color}{levelname:8s}{reset} "
  119. "{bold_cyan}{name}{reset}:"
  120. "{fg_bold_red}{lineno}{reset} "
  121. "{thin_yellow}{funcName} "
  122. "{thin_white}{message}"
  123. "{reset}",
  124. "style": "{",
  125. },
  126. "log": {"format": "%(asctime)s %(levelname)s %(message)s"},
  127. "json": {
  128. "()": "pythonjsonlogger.jsonlogger.JsonFormatter",
  129. "format": "%(levelname)s %(name) %(funcName) %(lineno) %(asctime)s %(message)s",
  130. },
  131. },
  132. "handlers": {
  133. "console": {
  134. "class": "logging.StreamHandler",
  135. "formatter": "color",
  136. "level": LOG_LEVEL,
  137. },
  138. "null": {
  139. "class": "logging.NullHandler",
  140. "level": LOG_LEVEL,
  141. },
  142. "file": {
  143. "class": "logging.handlers.RotatingFileHandler",
  144. "filename": "".join([LOG_FILE_PATH, "emus.log"]),
  145. "formatter": LOG_TYPE,
  146. "level": LOG_LEVEL,
  147. },
  148. "requests_file": {
  149. "class": "logging.handlers.RotatingFileHandler",
  150. "filename": "".join([LOG_FILE_PATH, "emus_requests.log"]),
  151. "formatter": LOG_TYPE,
  152. "level": LOG_LEVEL,
  153. },
  154. },
  155. "loggers": {
  156. # Quiet down our console a little
  157. "django": {
  158. "handlers": ["file"],
  159. "propagate": True,
  160. },
  161. "django.db.backends": {"handlers": ["null"]},
  162. "emus": {
  163. "handlers": ["console", "file"],
  164. "propagate": True,
  165. },
  166. },
  167. }
  168. REMOVE_FROM_SLUGS = ["_", " ", "/"]
  169. if DEBUG:
  170. # We clear out a db with lots of games all the time in dev
  171. DATA_UPLOAD_MAX_NUMBER_FIELDS = 3000
  172. GAME_SYSTEM_DEFAULTS = {
  173. "3do": {
  174. "name": "3DO",
  175. "retroarch_core": "opera",
  176. },
  177. "3ds": {
  178. "name": "Nintendo 3DS",
  179. "emulator": "drastic",
  180. },
  181. "atarijaguar": {
  182. "name": "Atari Jaguar",
  183. "retroarch_core": "virtualjaguar",
  184. },
  185. "atarilynx": {
  186. "name": "Atari Lynx",
  187. "color": "FFBF00",
  188. "retroarch_core": "handy",
  189. },
  190. "coleco": {
  191. "name": "Colecovision",
  192. "retroarch_core": "bluemsx",
  193. },
  194. "dreamcast": {
  195. "name": "Dreamcast",
  196. "color": "ED872D",
  197. "retroarch_core": "flycast",
  198. },
  199. "fds": {
  200. "name": "Famicom Disc System",
  201. "color": "B70E30",
  202. "retroarch_core": "nestopia",
  203. },
  204. "gb": {
  205. "name": "Game Boy",
  206. "color": "C0B8B1",
  207. "retroarch_core": "gambatte",
  208. },
  209. "gba": {
  210. "name": "Game Boy Advance",
  211. "color": "D5D5D5",
  212. "webretro_core": "mgba",
  213. "retroarch_core": "mgba",
  214. },
  215. "gbc": {
  216. "name": "Game Boy Color",
  217. "color": "77CCFF",
  218. "retroarch_core": "gambatte",
  219. },
  220. "gc": {
  221. "name": "GameCube",
  222. "color": "7461C7",
  223. "retroarch_core": "dolphin",
  224. },
  225. "mame-libretro": {
  226. "name": "Arcade",
  227. "color": "111111",
  228. "retroarch_core": "mame2010",
  229. },
  230. "mastersystem": {
  231. "name": "Sega Master System",
  232. "webretro_core": "genesis_plus_gx",
  233. "retroarch_core": "genesis_plus_gx",
  234. },
  235. "megadrive": {
  236. "name": "Genesis/Mega Drive",
  237. "color": "D03737",
  238. "webretro_core": "genesis_plus_gx",
  239. "retroarch_core": "genesis_plus_gx",
  240. },
  241. "model3": {
  242. "name": "Sega Model 3",
  243. "emulator": "Supermodel",
  244. },
  245. "gamgear": {
  246. "name": "Game Gear",
  247. "color": "3FA3C4",
  248. },
  249. "msx": {
  250. "name": "MSX",
  251. "retroarch_corre": "bluemsx",
  252. },
  253. "n64": {
  254. "name": "Nintendo 64",
  255. "color": "C76660",
  256. "webretro_core": "mupen64plus_next",
  257. "retroarch_core": "mupen64plus_next",
  258. },
  259. "nds": {
  260. "name": "Nintendo DS",
  261. "color": "39D0D0",
  262. "retroarch_core": "desmume",
  263. },
  264. "ngp": {
  265. "name": "Neo Geo Pocket",
  266. "retroarch_core": "mednafen_ngp",
  267. },
  268. "neogeo": {
  269. "name": "Neo Geo",
  270. "retroarch_core": "fbneo",
  271. },
  272. "ngpc": {
  273. "name": "Neo Geo Pocket Color",
  274. "retroarch_core": "mednafen_ngp",
  275. },
  276. "nes": {
  277. "name": "Nintendo",
  278. "color": "656565",
  279. "webretro_core": "nestopia",
  280. "retroarch_core": "nestopia",
  281. },
  282. "pcengine": {
  283. "name": "PC Engine/TurboGrafix 16",
  284. "color": "55B4CC",
  285. "retroarch_core": "mednafen_supergrafx",
  286. },
  287. "pcfx": {
  288. "name": "PC FX",
  289. "color": "55B4CC",
  290. "retroarch_core": "mednafen_pcfx",
  291. },
  292. "ps2": {
  293. "name": "Playstation 2",
  294. "color": "111CAA",
  295. "emulator": "PCSX2",
  296. },
  297. "psp": {
  298. "name": "Playstation Portable",
  299. "color": "",
  300. "retroarch_core": "ppsspp",
  301. },
  302. "psx": {
  303. "name": "Playstation",
  304. "color": "E9DD00",
  305. "retroarch_core": "mednafen_psx",
  306. },
  307. "ports": {
  308. "name": "Ports",
  309. },
  310. "saturn": {
  311. "name": "Saturn",
  312. "color": "0047AB",
  313. "retroarch_core": "mednafen_saturn",
  314. "emulator": "yabuse",
  315. },
  316. "scummvm": {
  317. "name": "ScummVM",
  318. "color": "E8B500",
  319. "retroarch_core": "scummvm",
  320. "emulator": "scummvm",
  321. },
  322. "sega32x": {
  323. "name": "Sega 32X",
  324. "color": "",
  325. "retroarch_core": "genesis_plus_gx",
  326. },
  327. "segacd": {
  328. "name": "Sega CD",
  329. "color": "",
  330. "retroarch_core": "genesis_plus_gx",
  331. },
  332. "snes": {
  333. "name": "Super Nintendo",
  334. "color": "A060C7",
  335. "retroarch_core": "snes9x",
  336. "webretro_core": "snes9x",
  337. },
  338. "virtualboy": {
  339. "name": "Virtual Boy",
  340. "color": "99AA11",
  341. "retroarch_core": "mednafen_vb",
  342. },
  343. "wii": {
  344. "name": "Wii",
  345. "color": "",
  346. "retroarch_core": "dolphin",
  347. },
  348. }