mirror of
https://github.com/jarulsamy/Plex-Bot.git
synced 2024-08-19 15:01:55 +02:00
allow executing outside of docker env by checking if user is root user for config path
This commit is contained in:
parent
a45ccb657e
commit
f8e5af87b6
@ -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
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user