-
Notifications
You must be signed in to change notification settings - Fork 0
/
load_env.py
44 lines (29 loc) · 1023 Bytes
/
load_env.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Copyright 2021-2024 AstreaTSS.
This file is part of PYTHIA.
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/.
"""
import os
from pathlib import Path
from dotenv import load_dotenv
IS_LOADED = False
__all__ = ("is_loaded", "set_loaded", "load_env")
def is_loaded() -> bool:
return IS_LOADED
def set_loaded() -> None:
global IS_LOADED
IS_LOADED = True
def load_env() -> None:
if is_loaded():
return
load_dotenv(override=True)
if os.environ.get("DOCKER_MODE") in {"true", "True", "TRUE", "t", "T", "1"}:
os.environ["DB_URL"] = (
f"postgres://postgres:{os.environ['POSTGRES_PASSWORD']}@db:5432/postgres"
)
file_location = Path(__file__).parent.absolute().as_posix()
os.environ["DIRECTORY_OF_FILE"] = file_location
os.environ["LOG_FILE_PATH"] = f"{file_location}/discord.log"
set_loaded()