From f8e5af87b68b904635a79eddeba49bef2de89c03 Mon Sep 17 00:00:00 2001 From: Carsten Burgard Date: Sun, 13 Feb 2022 12:04:34 +0100 Subject: [PATCH] allow executing outside of docker env by checking if user is root user for config path --- PlexBot/__init__.py | 8 +++----- PlexBot/__main__.py | 6 +++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/PlexBot/__init__.py b/PlexBot/__init__.py index badc36c..0b1228c 100644 --- a/PlexBot/__init__.py +++ b/PlexBot/__init__.py @@ -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 diff --git a/PlexBot/__main__.py b/PlexBot/__main__.py index 1434d00..57d1982 100644 --- a/PlexBot/__main__.py +++ b/PlexBot/__main__.py @@ -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"]