updating with latest changes to CONFIG

This commit is contained in:
dtomlinson
2019-12-04 11:50:55 +00:00
parent e2f07a0d9f
commit 3af8d00661
4 changed files with 61 additions and 19 deletions

View File

@@ -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)