Add config initializer
This commit is contained in:
parent
aeafc2db41
commit
d4a46ca5ad
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from json import load as jsonLoad
|
||||||
|
from TYPES import DirParserTypes, LogTypes
|
||||||
|
|
||||||
|
CFG_PATH = "config.json"
|
||||||
|
|
||||||
|
|
||||||
|
def loadCFG(config_path: str) -> dict:
|
||||||
|
with open(config_path, "r") as cfg:
|
||||||
|
return jsonLoad(cfg)
|
||||||
|
|
||||||
|
|
||||||
|
def loadParser(options: dict) -> tuple:
|
||||||
|
dirParser = None
|
||||||
|
parser_value = options["Main"]["DirParser"]
|
||||||
|
for av_parser in DirParserTypes:
|
||||||
|
if parser_value == av_parser.value:
|
||||||
|
dirParser = av_parser
|
||||||
|
if dirParser is None:
|
||||||
|
raise Exception(f"Directory parser '{parser_value}' not found")
|
||||||
|
else:
|
||||||
|
match dirParser:
|
||||||
|
case DirParserTypes.Jellyfin:
|
||||||
|
JellyfinConfig = {}
|
||||||
|
for i in options["JellyfinConfig"].keys():
|
||||||
|
JellyfinConfig[i] = options["JellyfinConfig"][i]
|
||||||
|
return dirParser, JellyfinConfig
|
||||||
|
|
||||||
|
|
||||||
|
configuration = loadCFG(CFG_PATH)
|
||||||
|
|
||||||
|
dirParser, JellyfinConfig = loadParser(configuration)
|
||||||
|
DBPath = configuration["Main"]["DBPath"]
|
Reference in New Issue