Skip to content

Feature implement config file override for webqueue2api configs #46

24 changes: 23 additions & 1 deletion src/webqueue2api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,24 @@
from webqueue2api.parser import Item, Queue, load_queues
from .config import config
from .config import config
import configparser, sys
from pathlib import Path as path
import webqueue2api.parser
import webqueue2api.api

config_parser_object = configparser.ConfigParser()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename config_parser_object to config_parser

config_file_location = path.joinpath(path(sys.executable).parent.parent.parent, "webqueue2api_config")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename config_file_location to config_file_path and add file extension.


if path(config_file_location).exists():
config_parser_object.read(config_file_location)

if config_parser_object.has_section("parser"):
if config_parser_object.has_option("parser", "queue_directory"):
webqueue2api.parser.config.queue_directory = config_parser_object["parser"]["queue_directory"]
if config_parser_object.has_option("parser", "queues_to_ignore"):
webqueue2api.parser.config.queues_to_ignore = config_parser_object["parser"]["queues_to_ignore"]

if config_parser_object.has_section("api"):
if config_parser_object.has_option("api", "environment"):
webqueue2api.api.config.environment = config_parser_object["api"]["environment"]
if config_parser_object.has_option("api", "jwt_secret_key"):
webqueue2api.api.config.jwt_secret_key = config_parser_object["api"]["jwt_secret_key"]