| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 | import dj_database_urlimport osfrom django.utils.translation import gettext_lazy as _from dotenv import load_dotenv# Tap emus.conf if it's availableif 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")from pathlib import Path# Build paths inside the project like this: BASE_DIR / 'subdir'.BASE_DIR = Path(__file__).resolve().parent.parent# Quick-start development settings - unsuitable for production# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/# SECURITY WARNING: keep the secret key used in production secret!SECRET_KEY = "l2-2d4dmvb0un0s)=5z%c87t*tg_hu&bt6*o^ks9r7f-3(mp$$"# SECURITY WARNING: don't run with debug turned on in production!DEBUG = os.getenv("EMUS_DEBUG", False)FEATURED_GAME_DURATION = os.getenv("EMUS_FEATURED_GAME_DURATION", 60 * 60 * 18)ALLOWED_HOSTS = ["*"]CSRF_TRUSTED_ORIGINS = [os.getenv("EMUS_TRUSTED_ORIGINS", "http://localhost:8000")]X_FRAME_OPTIONS = "SAMEORIGIN"REDIS_URL = os.getenv("EMUS_REDIS_URL", None)CELERY_TASK_ALWAYS_EAGER = os.getenv("EMUS_SKIP_CELERY", False)CELERY_BROKER_URL = REDIS_URL if REDIS_URL else "memory://localhost/"CELERY_RESULT_BACKEND = "django-db"CELERY_TIMEZONE = os.getenv("EMUS_TIME_ZONE", "EST")CELERY_TASK_TRACK_STARTED = TrueINSTALLED_APPS = [    "django.contrib.admin",    "django.contrib.auth",    "django.contrib.contenttypes",    "django.contrib.sessions",    "django.contrib.messages",    "django.contrib.staticfiles",    "django.contrib.sites",    "django_filters",    "django_extensions",    "markdownify.apps.MarkdownifyConfig",    "taggit",    "emus",    "mathfilters",    "search",    "games",    "rest_framework",    "allauth",    "allauth.account",    "django_celery_results",]SITE_ID = 1MIDDLEWARE = [    "django.middleware.security.SecurityMiddleware",    "django.contrib.sessions.middleware.SessionMiddleware",    "django.middleware.common.CommonMiddleware",    "django.middleware.csrf.CsrfViewMiddleware",    "django.contrib.auth.middleware.AuthenticationMiddleware",    "django.contrib.messages.middleware.MessageMiddleware",    "django.middleware.clickjacking.XFrameOptionsMiddleware",    "django.middleware.gzip.GZipMiddleware",]ROOT_URLCONF = "emus.urls"TEMPLATES = [    {        "BACKEND": "django.template.backends.django.DjangoTemplates",        "DIRS": [str(BASE_DIR.joinpath("templates"))],  # new        "APP_DIRS": True,        "OPTIONS": {            "context_processors": [                "django.template.context_processors.debug",                "django.template.context_processors.request",                "django.contrib.auth.context_processors.auth",                "django.contrib.messages.context_processors.messages",                "games.context_processors.game_systems",            ],        },    },]WSGI_APPLICATION = "emus.wsgi.application"DATABASES = {    "default": dj_database_url.config(        default=os.getenv("EMUS_DATABASE_URL", "sqlite:///db.sqlite3"), conn_max_age=600    )}CACHES = {    "default": {        "BACKEND": "django.core.cache.backends.locmem.LocMemCache",        "LOCATION": "unique-snowflake",    }}if REDIS_URL:    CACHES["default"]["BACKEND"] = "django.core.cache.backends.redis.RedisCache"    CACHES["default"]["LOCATION"] = REDIS_URLAUTHENTICATION_BACKENDS = [    "django.contrib.auth.backends.ModelBackend",    "allauth.account.auth_backends.AuthenticationBackend",]REST_FRAMEWORK = {    "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),    "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],    "PAGE_SIZE": 100,}LOGIN_REDIRECT_URL = "/"AUTH_PASSWORD_VALIDATORS = [    {        "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",    },    {        "NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",    },    {        "NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",    },    {        "NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",    },]# Internationalization# https://docs.djangoproject.com/en/3.1/topics/i18n/LANGUAGE_CODE = "en-us"TIME_ZONE = os.getenv("EMUS_TIME_ZONE", "EST")USE_I18N = TrueUSE_L10N = TrueUSE_TZ = True# Static files (CSS, JavaScript, Images)# https://docs.djangoproject.com/en/3.1/howto/static-files/STATIC_URL = "static/"STATIC_ROOT = os.getenv("EMUS_STATIC_ROOT", os.path.join(BASE_DIR, "static"))MEDIA_URL = "/media/"MEDIA_ROOT = os.getenv("EMUS_MEDIA_ROOT", os.path.join(BASE_DIR, "media"))ROMS_DIR = os.path.join(MEDIA_ROOT, "roms")COLLECTIONS_DIR = os.path.join(ROMS_DIR, "emulationstation-collections")SCRAPER_BIN_PATH = os.getenv("EMUS_SCRAPER_BINPATH", "Skyscraper")SCRAPER_CONFIG_FILE = os.getenv("EMUS_SCRAPER_CONFIG_FILE", "skyscraper.ini")SCRAPER_SITE = os.getenv("EMUS_SCRAPER_SITE", "screenscraper")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"]),            "formatter": LOG_TYPE,            "level": LOG_LEVEL,        },        "requests_file": {            "class": "logging.handlers.RotatingFileHandler",            "filename": "".join([LOG_FILE_PATH, "emus_requests.log"]),            "formatter": LOG_TYPE,            "level": LOG_LEVEL,        },    },    "loggers": {        # Quiet down our console a little        "django": {            "handlers": ["file"],            "propagate": True,        },        "django.db.backends": {"handlers": ["null"]},        "emus": {            "handlers": ["console", "file"],            "propagate": True,        },    },}REMOVE_FROM_SLUGS = ["_", " ", "/"]if DEBUG:    # We clear out a db with lots of games all the time in dev    DATA_UPLOAD_MAX_NUMBER_FIELDS = 3000GAME_SYSTEM_DEFAULTS = {    "3do": {        "name": "3DO",        "retroarch_core": "opera",    },    "3ds": {        "name": "Nintendo 3DS",        "retroarch_core": "citra",    },    "atarijaguar": {        "name": "Atari Jaguar",        "retroarch_core": "virtualjaguar",    },    "atarilynx": {        "name": "Atari Lynx",        "color": "FFBF00",        "retroarch_core": "handy",    },    "coleco": {        "name": "Colecovision",        "retroarch_core": "bluemsx",    },    "daphne": {        "name": "Daphne",        "retroarch_core": "daphne",    },    "dreamcast": {        "name": "Dreamcast",        "color": "ED872D",        "retroarch_core": "flycast",    },    "fds": {        "name": "Famicom Disc System",        "color": "B70E30",        "retroarch_core": "nestopia",    },    "gb": {        "name": "Game Boy",        "color": "C0B8B1",        "retroarch_core": "gambatte",    },    "gba": {        "name": "Game Boy Advance",        "color": "D5D5D5",        "webretro_core": "mgba",        "retroarch_core": "mgba",    },    "gbc": {        "name": "Game Boy Color",        "color": "77CCFF",        "retroarch_core": "gambatte",    },    "gc": {        "name": "GameCube",        "color": "7461C7",        "retroarch_core": "dolphin",    },    "mame-libretro": {        "name": "Arcade",        "color": "111111",        "retroarch_core": "mame2010",    },    "mastersystem": {        "name": "Sega Master System",        "webretro_core": "genesis_plus_gx",        "retroarch_core": "genesis_plus_gx",    },    "megadrive": {        "name": "Genesis/Mega Drive",        "color": "D03737",        "webretro_core": "genesis_plus_gx",        "retroarch_core": "genesis_plus_gx",    },    "model3": {        "name": "Sega Model 3",        "emulator": "Supermodel",    },    "gamegear": {        "name": "Game Gear",        "color": "3FA3C4",        "retroarch_core": "genesis_plus_gx",    },    "msx": {        "name": "MSX",        "retroarch_core": "bluemsx",    },    "n64": {        "name": "Nintendo 64",        "color": "C76660",        "webretro_core": "mupen64plus_next",        "retroarch_core": "mupen64plus_next",    },    "nds": {        "name": "Nintendo DS",        "color": "39D0D0",        "retroarch_core": "desmume",    },    "ngp": {        "name": "Neo Geo Pocket",        "retroarch_core": "mednafen_ngp",    },    "neogeo": {        "name": "Neo Geo",        "retroarch_core": "fbneo",    },    "ngpc": {        "name": "Neo Geo Pocket Color",        "retroarch_core": "mednafen_ngp",    },    "nes": {        "name": "Nintendo",        "color": "656565",        "webretro_core": "nestopia",        "retroarch_core": "nestopia",    },    "pcengine": {        "name": "PC Engine/TurboGrafix 16",        "color": "55B4CC",        "retroarch_core": "mednafen_supergrafx",    },    "pcfx": {        "name": "PC FX",        "color": "55B4CC",        "retroarch_core": "mednafen_pcfx",    },    "ps2": {        "name": "Playstation 2",        "color": "111CAA",        "emulator": "PCSX2",    },    "psp": {        "name": "Playstation Portable",        "color": "",        "retroarch_core": "ppsspp",    },    "psx": {        "name": "Playstation",        "color": "E9DD00",        "retroarch_core": "mednafen_psx",    },    "ports": {        "name": "Ports",    },    "saturn": {        "name": "Saturn",        "color": "0047AB",        "retroarch_core": "mednafen_saturn",        "emulator": "yabuse",    },    "scummvm": {        "name": "ScummVM",        "color": "E8B500",        "retroarch_core": "scummvm",        "emulator": "scummvm",    },    "sega32x": {        "name": "Sega 32X",        "color": "",        "retroarch_core": "genesis_plus_gx",    },    "segacd": {        "name": "Sega CD",        "color": "",        "retroarch_core": "genesis_plus_gx",    },    "snes": {        "name": "Super Nintendo",        "color": "A060C7",        "retroarch_core": "snes9x",        "webretro_core": "snes9x",    },    "virtualboy": {        "name": "Virtual Boy",        "color": "99AA11",        "retroarch_core": "mednafen_vb",    },    "wii": {        "name": "Wii",        "color": "",        "retroarch_core": "dolphin",    },}
 |