Initial commit
This commit is contained in:
42
serverside/helpers/config.py
Normal file
42
serverside/helpers/config.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import configparser
|
||||
from pathlib import Path
|
||||
#from serverside.consts import BASE_DIR
|
||||
|
||||
BASE_DIR = Path(__file__).resolve().parent.parent.parent
|
||||
CONFIG_PATH = BASE_DIR / "configuration.ini"
|
||||
|
||||
_config = configparser.ConfigParser()
|
||||
_config.read(CONFIG_PATH)
|
||||
|
||||
def get(section: str, key: str, fallback=None):
|
||||
try:
|
||||
return _config.get(section, key)
|
||||
except (configparser.NoSectionError, configparser.NoOptionError):
|
||||
return fallback
|
||||
|
||||
def get_int(section: str, key: str, fallback=None):
|
||||
try:
|
||||
return _config.getint(section, key)
|
||||
except (configparser.NoSectionError, configparser.NoOptionError, ValueError):
|
||||
return fallback
|
||||
|
||||
def get_float(section: str, key: str, fallback=None):
|
||||
try:
|
||||
return _config.getfloat(section, key)
|
||||
except (configparser.NoSectionError, configparser.NoOptionError, ValueError):
|
||||
return fallback
|
||||
|
||||
def get_bool(section: str, key: str, fallback=None):
|
||||
try:
|
||||
return _config.getboolean(section, key)
|
||||
except (configparser.NoSectionError, configparser.NoOptionError, ValueError):
|
||||
return fallback
|
||||
|
||||
def sections():
|
||||
return _config.sections()
|
||||
|
||||
def options(section: str):
|
||||
try:
|
||||
return _config.options(section)
|
||||
except configparser.NoSectionError:
|
||||
return []
|
||||
Reference in New Issue
Block a user