updating with latest changes to CONFIG
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
from plex_posters.library import export
|
||||
from plex_posters.__header__ import __header__ as header
|
||||
from typing import Callable, Union
|
||||
import os
|
||||
import toml
|
||||
|
||||
from plex_posters.library import export
|
||||
from plex_posters.__header__ import __header__ as header
|
||||
|
||||
|
||||
__all__ = []
|
||||
|
||||
|
||||
@@ -36,9 +38,9 @@ class Config:
|
||||
"""
|
||||
See :class:`~plex_posters.config.config.Config` for parameters.
|
||||
"""
|
||||
self.deferred_messages = []
|
||||
self.config_file = self.read_config(path)
|
||||
self.module_name = header.lower()
|
||||
self.deferred_messages = []
|
||||
|
||||
def read_config(self, path: str) -> Union[dict, None]:
|
||||
"""Reads the toml config file from `path` if it exists.
|
||||
@@ -73,16 +75,12 @@ class Config:
|
||||
|
||||
path += 'config.toml' if path[-1] == '/' else '/config.toml'
|
||||
path = os.path.expanduser(path)
|
||||
|
||||
try:
|
||||
with open(path, 'r+') as config_file:
|
||||
config_file = toml.load(config_file)
|
||||
return config_file
|
||||
except FileNotFoundError:
|
||||
try:
|
||||
self.defer_log(f'Config file not found at {config_file}')
|
||||
except UnboundLocalError:
|
||||
pass
|
||||
self.defer_log(f'Config file not found at {path}')
|
||||
pass
|
||||
|
||||
def get(
|
||||
@@ -108,7 +106,7 @@ class Config:
|
||||
Any
|
||||
Will return the config variable if found, or the default.
|
||||
"""
|
||||
env_key = f"{header}_{key.upper().replace('.', '_')}"
|
||||
env_key = f"{header.upper()}_{key.upper().replace('.', '_')}"
|
||||
# self.defer_log(self.config_file)
|
||||
|
||||
try:
|
||||
@@ -120,7 +118,7 @@ class Config:
|
||||
except KeyError:
|
||||
self.defer_log(f'{env_key} not found in config.toml')
|
||||
except TypeError:
|
||||
pass
|
||||
self.defer_log(f'{env_key} not found in config.toml')
|
||||
|
||||
# look for an environment variable
|
||||
value = os.environ.get(env_key)
|
||||
|
||||
Reference in New Issue
Block a user