allow executing outside of docker env by checking if user is root user for config path

This commit is contained in:
Carsten Burgard 2022-02-13 12:04:34 +01:00
parent a45ccb657e
commit f8e5af87b6
2 changed files with 8 additions and 6 deletions

View File

@ -1,8 +1,6 @@
"""
Plex music bot for discord.
Do not import this module, it is intended to be
used exclusively within a docker environment.
"""
import logging
import sys
@ -19,7 +17,7 @@ plex_log = logging.getLogger("Plex")
bot_log = logging.getLogger("Bot")
def load_config(filename: str) -> Dict[str, str]:
def load_config(basedir: str,filename: str) -> Dict[str, str]:
"""Loads config from yaml file
Grabs key/value config pairs from a file.
@ -35,12 +33,12 @@ def load_config(filename: str) -> Dict[str, str]:
"""
# All config files should be in /config
# for docker deployment.
filename = Path("/config", filename)
filename = Path(basedir, filename)
try:
with open(filename, "r") as config_file:
config = yaml.safe_load(config_file)
except FileNotFoundError:
root_log.fatal("Configuration file not found.")
root_log.fatal("Configuration file not found at '"+str(filename)+"'.")
sys.exit(-1)
# Convert str level type to logging constant

View File

@ -11,7 +11,11 @@ from .bot import General
from .bot import Plex
# Load config from file
config = load_config("config.yaml")
configdir = "config"
from os import geteuid
if geteuid() == 0:
configdir = "/config"
config = load_config(configdir,"config.yaml")
BOT_PREFIX = config["discord"]["prefix"]
TOKEN = config["discord"]["token"]