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

View File

@ -11,7 +11,11 @@ from .bot import General
from .bot import Plex from .bot import Plex
# Load config from file # 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"] BOT_PREFIX = config["discord"]["prefix"]
TOKEN = config["discord"]["token"] TOKEN = config["discord"]["token"]